Google Maps Geocoding i18n - google-maps

I'm using Google Maps Geocoding via json in my i18n website to validate event addresses and save them to ddbb.
https://developers.google.com/maps/documentation/javascript/geocoding
My main problem is that if an user (with english lang in browser) register an event address in Spain, I will get country as Spain instead of EspaƱa (and the same problem for adminAreas, city, etc).
For countries we have countryCode that solves the problem, but there isn't a code for cities. This results in duplicated (not related) cities in my ddbb.
Is there a way to get results in several languages in the same json request to be able to save translations?
There is the language parameter, but i don't think we can't put several codes separated by coma (because is not explained in documentation).
The only solution I've is make different requests for every lang in my site before save a new address.

We have now an optional parameter 'language' to tell google geocode api wich one to use:
https://developers.google.com/maps/documentation/geocoding/index#ReverseGeocoding
https://developers.google.com/maps/faq#languagesupport
Here you can find language codes supported:
https://spreadsheets.google.com/pub?key=p9pdwsai2hDMsLkXsoM05KQ&gid=1
geocoder.geocode( { 'address': addresInputField.value, 'language': 'es'}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
//do whatever with results
return true;
} else {
//do whatever with errors
return false;
}
});

Related

Cannot find POI via google-places-api that can be found on google-maps and google-plus

I am trying to find a specific listing via the google-maps-places API, but I don't get any results. This is strange to me, as there is a Google+ page and also a google-maps entry.
Let's take a look at the links:
Google+:
https://plus.google.com/115673722468988785755/about
Maps:
https://www.google.de/maps/place/AMWAY+Beratung+%26+Vertrieb+Haegebarth/#53.171976,9.465828,17z/data=!3m1!4b1!4m2!3m1!1s0x47b106116fc69d69:0xe17811ab2780c71d
If I use the very same coordinates from the maps entry in my nearby search and use the name from the entry as the keyword (or location for what it's worth) the results is empty.
Places-API (with exact same coordinates):
https://maps.googleapis.com/maps/api/place/nearbysearch/json?sensor=false&radius=2000&name=amway&location=53.171976,9.465828&language=de-DE&key=YOURKEY
I can of course imagine that the db for the Google+ POIs is a different one. But then again I don't see how the maps api does not find what I can find on the maps web app.
Thanks a lot for any help!
Try something like this:
map.places.nearbySearch({
location: latLng,
rankBy: google.maps.places.RankBy.DISTANCE,
types: ['shop'], // optional
name: "AMWAY Beratung & Vertrieb Haegebarth" // optional
},function(results, status){
if (status == google.maps.places.PlacesServiceStatus.OK) {
// The thing you need should be result[0]
// console.log(results[0]);
if (results[0].name == "AMWAY Beratung & Vertrieb Haegebarth") { // optionally check the type
// You have your place :)
}
}
}
What a workaround! Rumours are that the Google Maps JS API v3.20 or later will allow us to trigger click events on POIs, thereby getting Place objects directly.

DirectionsService - OVER_QUERY_LIMIT after 3 request?

This is my code :
function traceRoute(part, arr) {
var polylineTrattaTreno = new Array();
var request = {
origin: part,
destination: arr,
travelMode: google.maps.TravelMode.TRANSIT
};
directionsService.route(request, function (response, status) {
if (status == google.maps.DirectionsStatus.OK) {
... manage my data
} else {
console.log(status);
}
});
}
and I noticed that if I call this function 3 times, all is ok! Than I always get OVER_QUERY_LIMIT. Tried on putting timeout of 1 or 2 seconds. But nothing happens. Seems that I can't do more than 3 request for time?
According to the Documentation-
Use of the Google Directions API is subject to a query limit of 2,500
directions requests per day. Each directions search will count as a
single request against your daily quota when the mode of
transportation is driving, walking or cycling. Searching for transit
directions will count as 4 requests.
Adding to it-
Additionally, note that Directions API URLs are restricted to 2048
characters, before URL Encoding. As some Directions service URLs may
involve many locations along a path, be aware of this limit when
constructing your URLs.
Your origin and destination values might be quite distant and also considering the fact you are using transit direction, causing the limit being reached soon.
Update- If you set the mode to "transit" you must also specify either a departure_time or an arrival_time.

Asynchronous Call not working in Coffee Script

I am using CoffeeScript, Backbone.js and Google Maps API to reverse geocode a lat / lng
I have the function
country: (origin, callback) ->
#geocoder = new google.maps.Geocoder
#geocoder.geocode(
'latLng': origin,
(results, status) =>
if status is google.maps.GeocoderStatus.OK
callback(result[6])
else alert("Geocode was not successful for the following reason: " + status);
)
When I call this I use:
#country(origin, (data) =>
console.log(data.formatted_address)
)
btw:
origin = new google.maps.LatLng(origin_lat, origin_lng)
This does not work, it does not even seem to call it. I have the call back function under (data) but can not get it to work...
Thanks
Not sure about the overall context of your question, but I will take a stab at it anyway.
The way you've defined your country function, it will typically be part of an object or map. If you just want a standalone function, try:
country = (origin, callback) ->
...
Then when calling it, try to replace #country(...) with country(...).
Based on the comments, your call to geocode also looks wrong. You need to create an instance of GeocoderRequest and pass it instead of the 'latLng': origin pair. Unfortunately I haven't used the Google style APIs much, so if this is your real question I'm not much use to you.

Write a location and get the geocords, not working properly? JS

Link removed
This is my site. Im working on so you can enter a location on the search input field, and then see theres xx km from a restaurant.
Now i got almost everything working. If you see the source code you can see how it works. It showAddress(what you searched). And then show addresses makes it into lat/lng cords, and pass it to computeRestaurants() which computes the distances between the location you entered and the restaurants.
Somehow, when I run:
computeRestaurants(new google.maps.LatLng(55.662133, 12.508028));
outside the functions, it works and gives correct values.
But when i do:
showAddress('Valby'); // (like in the source code)
You can see that it returns NaN. And inside showAddress() it executes the same command as the one i wrote above computeRestaurants( the point )
So why will it not work properly?
point in showAddress is: (55.662133, 12.508028) so it is already converted to LatLng cords and therefore no need to new google.maps.latlng(...
My only bet right now is the brackets () ??
replace your showAddress by this:
var geocoder;
function showAddress(address)
{
if (typeof(geocoder) == 'undefined') geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
computeRestaurants(results[0].geometry.location);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
You are using mixup of v2 and v3 apis, and that is the problem.

Google Maps V3 Route Destination Mark Edit

Using the google.maps.DirectionsService.route() and google.maps.DirectionsRenderer.setDirections() method, is it possible to change the text on the info window for the destination, without creating a custom parser for the journey?
I couldn't see anything in the API which allowed you to access the markers of the route.
I don't want any code, just yes/no, and a hint for the right direction to take.
Current Function:
var request = {
origin: origPoint,
destination: new google.maps.LatLng(dest.lat(), dest.lng()),
travelMode: google.maps.DirectionsTravelMode.DRIVING,
region: "GB"
};
directionsService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(result);
}
});
Thanks,
Psy
I'm afraid that the api doesn't offer a direct way to access the info windows or access the markers.
But there are several ways to achieve that parsing parts of the result data:
I guess the simplest way to change text on the info window is to overwrite the DirectionsLegs' start and/or end addresses of the DirectionsResult. You have to do it before calling directionsDisplay.setDirections(result).
Or you can display just the polyline (see suppressMarkers and suppressInfoWindows of renderer's options) and create the markers and infowindows yourself - you have to access data from DirectionsLegs of DirectionsResult.
I would prefer the second way since it's cleaner and you have more freedom in adjustments. The first way, it's only a hack and you are just changing the text.