Reputation: 1247
I'm writing a web application using the google maps api v3, which displays places of interest for my customers. These won't be places which appear on google maps, and I want users to be able to filter the results to match their specific needs.
I've got it working so that the map centres on the user's current location on load. However, it does allow them to type in another address if they wish. When I do this, the map default to results in the American region.
Is there any way to get the region parameter for the map from the user's current location and use this to get more relevant results?
Another function I would like to implement is searching only for results within a certain (user-specifiable) distance from the given location. Currently all the places are stored in a MySQL database (with their address, latitude and longitude) and I iterate through all places and use this formula to determine the distance. I anticipate that I might get 50,000 places in the database.
Should I be worried about response time for this calculation, and is there a way I can make it quicker? Is having my data stored in a MySQL database a good idea in general for this kind of application?
Upvotes: 0
Views: 546
Reputation: 23977
Biasing geocoder results:
To bias the geocoder results, you can use navigator.language
as the region
parameter. It should provide more relevant results to the user.
Other way to improve the results might be by using the user's current location. You can use viewport biasing to improve the results (you can calculate some bounding box around the user's current location).
Using user's current location to acquire value for the region
parameter is problematic. I'm not aware if there is some public API to acquire IANA language subtag from a location. But you can use the reverse geocoder to translate the location, then extract a country code from the results. The problem is that some country codes doesn't match the IANA language subtags that are required (e.g. ca is the country code for Canada but language subtag for Catalan, Valencian). However most of the time using the country code instead of language subtag should improve the results.
Storing latlng in MySQL db:
I'm afraid that iteration through all places and applying the Haversine formula might be very time consuming (some study about it here).
Probably the best way to handle laglng data in MySQL is to use spatial extensions. A nice blog post about using it.
Upvotes: 1