Reputation: 10111
I have recently developed an application that uses Google maps APi v3, in order to allow my customers to specify their location, and to indicated this location on the map upon the request of their users(end users).
Now, I have 2 issues:
I'm using the API in 2 languages, and sometimes they are getting messed up, and get pretty much ugly.
Now, optimally, I would like to allow the user to change the language of the map in real time, allowing to add locations in both of the languages, depending on the needs of the end users(the users of my users), but from a research the I have conducted, it appears to be impossible, unless you make a second call for the API in the same page, and I am not into violating Google's terms of use.
What I've come up with, is that I need to get each location Geo-coded, and then translated to the other language, then I'll be able to use the appropriate location name for each user and page.
The second issue, is that Google doesn't seem to recognize a non specific type of location, on global level. Let's say that I type 'United states of America' or 'Europe', now, some users would liker to display just that, instead the Google API seems to complete the address to something like: 'Texas, united states', or 'Stockholm, Sweden, Europe'. That's the location that it places the marker on, and I suppose that this is what Geocoding does, fetching a specific location, but is there a good, bug - proof way around it, instead of analyzing the input text of the user perhaps, or somehow filtering and manipulating the result from the API, which is clearly a violation of the terms of use?.
Thanks in advance guys!, I've been smashing my head into the wall over this for the past couple of weeks.
Upvotes: 0
Views: 427
Reputation: 9788
Here is example where I geocode and swap between two contries, plus print geocode debug stuff using
console.log(results[0]);
and also,
alert('Got formatted to: ' + results[0].formatted_address);
"Europe" and "United states" should be present. Marker are placed to latLng values which geocoding returns.
It uses gmap3 library to launch a map since its an example I recently build, but all the relevant stuff is normal google maps geocoding code. Use it as you like.
Check out JS fiddle (geocode using country name)
In order to geocode based on visible viewport you need to get and pass current bounds for geocoder, I created an example which geocodes viewport bounds and centers map to position based on actual geocoder result.
Check out JS fiddle (geocode using viewport bounds)
Upvotes: 1
Reputation: 7635
You can use the Geocoder API of Google Maps
You define the geocoder like that:
geocoder = new google.maps.Geocoder();
Take a look at this example: http://geocodezip.com/v3_zoom2countrySelectList.html for the following
Upvotes: 1