Google Maps Distance Matrix wrong result - google-maps

I am performing a request to the Google Maps Distance Matrix API to calculate the distance from one point to another. Both points are in Russia. The problem is that, in some cases, the API returns the wrong destination.
For example, I select this point on the Black sea coast, Russia.
The request to the API is
https://maps.googleapis.com/maps/api/distancematrix/json?origins=58.3941198,33.223535&destinations=44.58019749055891,38.0705451965332&mode=driving&language=ru-RU&key=
It returns
"destination_addresses" : [
"1 Chome-11 Kamifukubara, Yonago-shi, Tottori-ken 683-0004, Japan"
],...
So, Google Maps knows it is Russia, but Distance Matrix thinks it is Japan. Why?
Is there a known bug for places near the sea coast?
UPDATE
This bug was handled in issue tracker https://issuetracker.google.com/issues/35828610.
It was marked as Fixed on July 19, 2016.

Good news and bad news :)
The bad news is that the Japanese address will come up for many remote locations, as this is an on-going issue in the Geocoding API.
This has been reported in the Google Maps API issue tracker:
https://code.google.com/p/gmaps-api-issues/issues/detail?id=9683
Take a look at this comment on the issue tracker for details on how to workaround this.
The good news is that you still get the correct distances and route from Distance Matrix API and Directions API.

The problem with this Japan location is its bounds which say it is all around the world:
"formatted_address" : "1 Chome-11 Kamifukubara, Yonago-shi, Tottori-ken 683-0004, Japan",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 90,
"lng" : 180
},
"southwest" : {
"lat" : -90,
"lng" : -180
}
},
"location" : {
"lat" : 35.4426127,
"lng" : 133.3638089
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 90,
"lng" : 180
},
"southwest" : {
"lat" : -90,
"lng" : -180
}
}
},
"place_id" : "ChIJlwBC99P3VjUReuUmCg7qU_E",
"types" : [ "sublocality_level_3", "sublocality", "political" ]

Related

Google Place API not showing current result when I tried to search for AnimalClinics

Initially I tried
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=19.031959,%2072.895695&radius=10000&type=school&sensor=true&key=AIzaSyCjQ03Ldxx9c55QmQ7ANGKRhEL*********s
this url and this showed right result
"rating" : 3.4,
"reference" : "ChIJSSUqsiDG5zsRyRBoSTT6WaA",
"scope" : "GOOGLE",
"types" : [ "point_of_interest", "school", "establishment" ],
"user_ratings_total" : 21,
"vicinity" : "Janardhan Krishna Karmalkar Marg, Brindavan Colony, Chembur West, Mumbai"
},
But when I tried to search for animal clinic it is showing some weird location.
My url:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=19.031959,%2072.895695&radius=10000&type=AnimalClinics&sensor=true&key=AIzaSyCjQ03Ldxx9c55QmQ7ANGKR********
result:
"name" : "Nishraj Insurance Services",
"opening_hours" : {
"open_now" : true
It is working fine only with School, Hospitals and Hotels location but I have to show the location of nearest Animal Clinics and Milk Dairy.
This behavior is working as intended because Animal Clinic is currently not supported in Place Types, you may visit the docs here to see the current supported place types.
The possible place type for you is veterinary_care
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=19.031959,%2072.895695&radius=10000&type=veterinary_care&sensor=true&Key=YOUR_API_KEY
The result would be:
rating: 3.9,
reference: "ChIJVVVVlffO5zsR9rpcrHikEzs",
scope: "GOOGLE",
types: [
"veterinary_care",
"point_of_interest",
"establishment"
],

Google Maps Distance Matrix API - Not Returning long/lat in response

Trying out the Google Maps Distance Matrix API for calculating the time between the origin and destination and I'm using this API
https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=32.988777,xxxx&destinations=32.988777,xxxx&key=myAPIKey
(xxxx - I'm providing a valid value just masking it on here)
I am getting a response as
{
"destination_addresses" : [ "Plano, TX 75024, USA" ],
"origin_addresses" : [ "Coppell, TX 75019, USA" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "13.4 mi",
"value" : 21636
},
"duration" : {
"text" : "14 mins",
"value" : 833
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
But I'm unable to correlate the req and response as the response is missing the long/lat, How do I solve this issue?
Per official documentation: DistanceMatrix service does not include lat/lng element in response. See all available elements here: https://developers.google.com/maps/documentation/distance-matrix/intro#DistanceMatrixResponses
Nonetheless, looking at your request, it appears that you already supplied lat/lng in your input. On the other hand if you supplied address as origins/destinations and aiming to extract the corresponding coordinates, then you can simply do forward Geocode afterwards.

Google Maps Distance Matrix API returns different output compared to Google Maps

I am tinkering with Google Maps APIs using web services and noticed, that I get different output from Google Maps Distance Matrix API compared to Google Maps.
This is what I mean:
https://maps.googleapis.com/maps/api/distancematrix/json?origins=Batilly&destinations=Cherbourg&language=en&key=AIzaSyAtYy7eYoooIzYGvFl15xRP2xHAdMU0-1c
this is what my query returns:
{
"destination_addresses" : [ "Cherbourg, France" ],
"origin_addresses" : [ "Batilly, France" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "195 km",
"value" : 194751
},
"duration" : {
"text" : "2 hours 3 mins",
"value" : 7373
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
And this is what Google Map returns:
So instead of 708 kilometers I get 195 kilometers. The problem is with Batilly city. Cherbourg coordinates are good.
Real Coordingates of Batilly are 49.171029, 5.969359(Google Maps output)
Google Maps Geocoding returns 48.7486861, -0.14727
How should I configure my Google Maps Distance Matrix API so it would return the same output as Google maps does ?
There obviously are more than 1 city named Batilly in france.
To get a result similar to Google Maps you may:
get the location via a Places-TextSearch.
For me it returns the desired location(49.1710200,5.9693580)
use this location in the DistanceMatrix- request

Inconsistent language in Google Place Details API

I'm using Google Place Details API on my server to store information about a place, using the placeId sent by a client.
I'm facing an issue regarding the language of the result, which differs when the place is a city or an address in that city, even when the language is specified in the query. For example:
The place id ChIJ53USP0nBhkcRjQ50xhPN_zw is the city of Milan, and the API returns Milan as locality and Lombardy as administrative area (English names)
The place id EjBWaWEgZGVsbGEgU3BpZ2EsIE1pbGFuLCBQcm92aW5jZSBvZiBNaWxhbiwgSXRhbHk is a street in Milan, and the API returns Milano as locality and Lombardia as administrative area (Italian names)
To make it even weirder, both searches return Italy as country. Is this the expected behavior of the API?
Is this the expected behavior of the API?
Yes, this is expected result. Even if you specify a language, it will return the response in that language only if there is one available, if not it will return the response in the language it was originally entered in.
Case 1:
Milan: As a Milan is city. Therefore,there are available results in almost every language. Almost all the major city through out the world have results in every language. By default, you will get result in English.
Case 2:
Via della Spiga: As it is a street. Right now, the results are only available in Italian as they were most possible entered in Italian.
Result when you search "Via della Spiga" in Google Map:
To learn more about this:
Translation of Places information into language specified by request. In this a request for a feature is asked that tells the developer in which language the results are so that they can take care of data accordingly, I personally think that would be great till the issue has not been fixed.
language parameter in place/details request not working
Both of the above issues are about 2 year old. Yet, Google is unable to resolve this issues.
One way to possibly solve this problem is by using textsearch:
As you can convert most of administrative area/city into any language name by using textsearch:
`https://maps.googleapis.com/maps/api/place/textsearch/json?query=Lombardia&lang‌​uage=Your_language&key=YOUR_API_KEY`
Example: Converting "Lombardia" into a chinese language:
https://maps.googleapis.com/maps/api/place/textsearch/json?query=Lombardia&language=zh-CN&key=YOUR_API
{
"html_attributions" : [],
"results" : [
{
"formatted_address" : "意大利伦巴第",
"geometry" : {
"location" : {
"lat" : 45.47906709999999,
"lng" : 9.8452433
},
"viewport" : {
"northeast" : {
"lat" : 46.6351853,
"lng" : 11.4276993
},
"southwest" : {
"lat" : 44.6796491,
"lng" : 8.4978605
}
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id" : "02401d0909d69ca5c69de799e193caf84acc41f9",
"name" : "伦巴第",
"place_id" : "ChIJf4M-GsNEgUcR1JMVKCIm8qY",
"reference" : "CoQBfQAAAEKCAV-1Ec-V2ZfnWsCk_elhlEXckc_k94jBYlU7k5ivhrqPlWd24aSAa5fqNTfwKKhU0wSsZFv42aMm1BrG5wEwZNGKwFqELxMEt0ye7KFfBgVtfHZbqeiBx3hEH8Iq60wwW--edqpROkBTjHrxIwisCGJwhCzKKkQ9H6FdfW_aEhAnmI0ZOFk1KGaGms4IqTOiGhRX5iErBIwnmLos4U9Ggs325MmcEA",
"types" : [ "administrative_area_level_1", "political" ]
}
],
"status" : "OK"
}
Lombardia in chinese is 意大利伦巴第
When you search for placeID details, you get address_components array:
"address_components" : [
{
"long_name" : "Via della Spiga",
"short_name" : "Via della Spiga",
"types" : [ "route" ]
},
{
"long_name" : "Milano",
"short_name" : "Milano",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Milano",
"short_name" : "MI",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Lombardia",
"short_name" : "Lombardia",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Italy",
"short_name" : "IT",
"types" : [ "country", "political" ]
}
]
So if you loop over the above array and use textsearch then you will get almost consistent address in a particular language.
I think you can use some Optional parameters to set what language you want, such that:
A Nearby Search request is an HTTP URL of the following form:
https://maps.googleapis.com/maps/api/place/nearbysearch/output?parameters
put language parameter, such that:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=cruise&language=en
For more detail, please refer here.

How to get JSON from URL in Google App Engine Java

I want to get json from url in google app engine, can u tell me some quite simple methods to do this, thanks, sr my english not good
URL
Content:
{
"debug_info" : [],
"html_attributions" : [ "Listings by \u003ca href=\"http://www.diadiem.com/\"\u003eDiadiem.com\u003c/a\u003e" ],
"next_page_token" : "ClRMAAAAl7MjfntXhFEi33IPPcZJJ5fYfiJzIIGggr9Xc6A_sKeTrjohJntaaG1jWaGYMKiZYruuoqTVipUZFaLhpNXZbhYloN6SeS44epx3lPRdpuMSEHWJTSO2ShwXOz6bjg0xefcaFOUN9wK6NE5Dykjx-x-VLypkBMRH",
"results" : [
{
"geometry" : {
"location" : {
"lat" : 16.058660,
"lng" : 108.2191410
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "7064cb3f44db62207fc2bd83579b63ca9552e658",
"name" : "Vietcombank - Atm",
"reference" : "CnRwAAAAHU3y6j7CocExwcFq6DKtkS2SFT-0X23E7C9M7bpHk2EF04ShIX7IRNl9TwGF_APSwaKmk8XSZIGm52ajXnpKhj15i48w0BHmJR0ZamJdIAi3iJD_sExjjHkf5Lnfxq4iLroTAmQyRAoAVG7dMwVeTRIQcO_Qq9N85d96vQCtEdZjyRoUbETiZPHxkSjkbD9CVnQh6N_8yUA",
"types" : [ "establishment" ],
"vicinity" : "272 Phan Châu Trinh"
},
{
"geometry" : {
"location" : {
"lat" : 16.0602490,
"lng" : 108.21470
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "bd20b9fbd718c13ee3f6d404c3004b649130df4a",
"name" : "ATM DongA Bank",
"reference" : "CnRtAAAAP9XTDfjgtqvahglz24j2posRRCR9ry56xyAd0FX810ZeyiKWeEi4Btfnfycb23Sa6x_grdjJszB7Xf80jFBrer9kHYQHsKX2-spx9LHn_yrZxlfC7wxHOdUt9YbYMp71fzQ_SJOC9W1Hj2cHHi9g0BIQPrdWzJvelD1NDEcC49Q8eRoUE0juanyzeZHjyYbnozUGB13RySk",
"types" : [ "atm", "finance", "establishment" ],
"vicinity" : "Nguyễn Văn Linh, Da Nang"
},
Not sure if I got your question correctly, but if you are trying to parse Google's JSON response, a good and easy way to do it may be to use jQuery parseJSON function.
You can also take a look at this answered question to see sample code.
Also, not explicitly stated in the "answered question" link above - you cannot just access the json (or xml) from within your web page code even though you can use the url manually in a browser to get the json data (as it seems you have done in your post). There are various security aspects and Google will not even send the data requested that way (I believe it is call cross-site-scripting - Google it for more details). It has to go - as in the example linked above, from you web page to your server, have the server do the request to Google to get the data, have the server then post this back to your site/ web page (through AJAX or just a new page - however you are doing things on your site).
That's the sloppy and non-technical, but I wasted all day Sunday trying to get around this until I understood the issue and what I was supposed to (and had to do). This might not be what you are referring to but I think it may indeed be. If so I hope it helps. Cheers