Keyword

Search for K2 Item by Location

  • Pastey
  • Pastey's Avatar Topic Author
  • Offline
  • New Member
More
12 years 6 months ago #65911 by Pastey
Search for K2 Item by Location was created by Pastey
Hi Guys,

Im building a fairly large public blog at the moment with k2 and one requirement is that a user must be able to refine their search by location or preferably the returned results are ordered by location (closest first). Every item will have a postcode and this will be stored within an extra field.

I wondered if anyone on here had come up against anything like this and could give me some directions as to where to start. Ive looked at the google maps api but there are some fairly restrictive limits in terms of usage, is there a better way to achieve this? Is there an extension that already does this (ive looked on JED but cannot see anything)? Or is there another service which may be better than googlemaps?

One thought i did have was to create another table in the db, workout and store the long lat values of the postcodes on content input and then do a calculation within the search (before returning the results) which would determine the ordering of the results. Is this even possible?

Cheers,
Pastey

Please Log in or Create an account to join the conversation.

More
12 years 6 months ago #65912 by william white
Replied by william white on topic Re: Search for K2 Item by Location
This is fun Math:) www.movable-type.co.uk/scripts/latlong.html
Not sure how to implement what you want, but it seems to me that you would first have to determine how far every item is from the entered zip code, store that in an array along with the record numbers for the items, then call up each record number with a foreach loop inside an override along with a title link to the item/s

Please Log in or Create an account to join the conversation.

More
12 years 6 months ago #65913 by Aimery Marsily
Replied by Aimery Marsily on topic Re: Search for K2 Item by Location
The biggest issue you will have (I have the same) is to be able to sort your K2 items in the K2 page by your extra-field value, there are no custom way of outputting the content. It's only by the default given value like Alphabetic, New first, etc... no way, except by hacking the core to create a custom output content and display it with the K2 template....

For your system of geolocation you can use the powerfull JSON output from the GoogleMap API : developers.google.com/maps/documentation/geocoding/

I use it to store in an extra field the Lat and Long of my item (realestate like system). I have a param in my items that contain the ZipCode and I use the JSON to get the Lat and Long and save it with them on the fly : ZIPCODE / LAT / LONG.

If you find a native way for the ordering I'll thank you ;-)

Please Log in or Create an account to join the conversation.

  • Pastey
  • Pastey's Avatar Topic Author
  • Offline
  • New Member
More
12 years 6 months ago #65914 by Pastey
Replied by Pastey on topic Re: Search for K2 Item by Location
yeah its a tough one. I found this (not sure if there's an equivalent US method):

www.hexcentral.com/articles/postcodes-distances.htm

So i can use a separate table to store an item reference and the x and y's (grab this data on content input). That way i can use a JOIN in the sql and sort the returning records by distance. This would work for something like a related items module, not sure how to approach the actual search result sorting. When i do figure something out ill post it back on here.

Thanks for the help, much appreciated!

Please Log in or Create an account to join the conversation.

More
12 years 6 months ago #65915 by william white
Replied by william white on topic Re: Search for K2 Item by Location
It therefore doesn't take account of the curvature of the earth

Awww, don't we want a formula to do that as well?
Im sure it will create a regular expression headach

Please Log in or Create an account to join the conversation.

  • Pastey
  • Pastey's Avatar Topic Author
  • Offline
  • New Member
More
12 years 6 months ago #65916 by Pastey
Replied by Pastey on topic Re: Search for K2 Item by Location
Well the Haversine calculation means that i could store just long lat which is better later on in case i need to use googlemaps api on so ill have a go, let you know the results.

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum