Google Directions API Result is different from Google Maps result - google-maps

I am developing an app that displays the Distance & path between 2 distances. In this case I have used following addresses:
Source: Major Bhola Ram Enclave
Destination: Ring Road Mall, Sector 3, Rohini, New Delhi, Delhi
When I use Directions API then I get following result, see image below:
But, when I search these addresses in Google Maps then I get different Result.
Click here to see Google Maps result
I searched a lot about this but I couldn't find any reason/solution for this.
Please guid me in right direction.
Thanks.

Those are not addresses, they are places. If you want a similar result to Google Maps, you need to use the placeId or the coordinates returned for that place from the places service in the directions request.
http://www.geocodezip.com/v3_example_geo2.asp?addr1=Major%20Bhola%20Ram%20Enclave&addr2=Ring%20Road%20Mall,%20Sector%203,%20Rohini,%20New%20Delhi,%20Delhi&place=1&place=2
(uses the results from the place service)

Related

Google Places API: retrieve restaurant in Rome

It's hard for me to understand why Postman is returning me restaurant in US even if I'm restricting the research to postal_code:00100|country:IT (00100 = Rome zip code, IT = Italy)
This is my GET:
https://maps.googleapis.com/maps/api/place/textsearch/json?query=restaurant&components=postal_code:00100|country:IT&key=MYSECRETKEY
Where am I wrong?
The components filtering is not supported in Places API text search.
Take a look at official documentation, there is no components parameter available:
https://developers.google.com/places/web-service/search#TextSearchRequests
To bias your results you should use the location and radius parameters.
The components filtering is supported only in Geocoding API. So you can solve the issue in two steps.
Get position of the postal code using Geocoding API
Search restaurants using Places API text search and location from the first step
E.g.
Get location of postal code 00100
https://maps.googleapis.com/maps/api/geocode/json?components=postal_code%3A00100%7Ccountry%3AIT&key=YOUR_API_KEY
Now use coordinate 41.9228369,12.5014301 to search restaurants in 5km radius
https://maps.googleapis.com/maps/api/place/textsearch/json?query=restaurant&location=41.9228369%2C12.5014301&radius=5000&key=YOUR_API_KEY
Hope this helps!

Why do I get different result from geocode api vs google maps

I am new to google geocode API but I am planning to use the free version to get map coordinates for nearby golf courses. I started with my home course:
http://maps.google.com/maps/api/geocode/json?address=Karlstad+golfklubb
Plus "&key=[my generated api key]"
I get a result with status="OK" but the resulting long/lat is not correct. It's near but misses with 7-8km.
When I use maps.google I get correct location. Searched for "Karlstad golfklubb".
https://www.google.se/maps/place/Karlstad+Golfklubb/#59.4346545,13.5140563,17z/data=!3m1!4b1!4m2!3m1!1s0x465cb41aca8c1467:0x64836d18f18df2f6
Why do I get different geo locations when using the same keywords. Do they operate on different databases or do I need to enter more params?
I also tried with other nearby courses like "sommarro" and "bryngfjorden" but for they I get zero result. But no problem finding them in google maps.
If you look at the JSON code, they describe the formatted_address as
"formatted_address" : "Karlstad Golfbanan Jako, 652 30 Karlstad, Sweden"
Which if you enter into Google Maps shows the correct longitude and latitude in the JSON.
https://www.google.com/maps/place/Karlstad+Golfbanan+Jako,+Sweden/#59.3602394,13.472185,17z/data=!3m1!4b1!4m2!3m1!1s0x465cb23bc0f46911:0x66ceae446bdc95dc

Google maps places/geocode API missing data for place

When I search on maps.google.com for the address "21-6 Udagawacho, Shibuya, Tokyo Prefecture 150-0042, Japan", it comes up with a result that is the correct result at that exact address.
When I try querying google maps geocoder as well as place service with the same address, however, I always get no results. I've tried the geocoder as well as textSearch and radarSearch for the place service API.
Since the correct result came up on maps.google.com I know that google has the data for the place but why does it not come up in the API queries?

google map and api shows different results

I am surprised whether i am doing any wrong or not. When i am finding the distance between two locations on google maps say maps.google.co.uk and when i query their API i get different result. Am i missing somethng?
Origin:Hyde Park Corner Station, Knightsbridge, London, United Kingdom
Destination:The Ritz London, United Kingdom
Result: 1.2 miles
And when i am using api:
http://maps.googleapis.com/maps/api/directions/json?origin=Hyde%20Park%20Corner%20Station,%20Knightsbridge,%20London,%20United%20Kingdom&destination=The%20Ritz%20London,%20United%20Kingdom&region=gb&sensor=false&alternatives=true&units=imperial
Result:4.3 miles or 5.0 miles etc.
Why is there so much of difference . Am i missing something.
There are significant differences between Google Maps and a service like directions(or geocoding)
Google Maps at first is an implementation of Google Places, and that's the issue here. The directions-service uses geocoding to resolve the addresses, while Google Maps uses the PlacesService.
When you draw the route using the directionsRenderer, you will see that there are different start-and end-locations.
But when you first request the PlacesService to get the coordinates of the places, and use these coordinates to request the directionsService, you will get a result near by the result of Google Maps(the duration may differ, because the directionsService by default will not return results depending on the current traffic)

Google Maps API Driving Directions

I use Google Maps API and I have a map with 20 points on it.
Can I find an API call to give me driving directions and draw lines between them?
Yes, it can be done. The Google Maps API Documentation describes how to this very accurately:
"You can add the ability to calculate directions (using a variety of methods of transportation) by using the GDirections object. The GDirections object requests and receives direction results using either query strings (e.g. "New York, NY to Chicago, IL") or textual lat/lons.
The GDirections object also supports multi-part directions using a series of waypoints. Directions may be displayed as either a polyline drawing the route on a map, as a series of textual description within a <div> element (e.g. "Turn right onto the Williamsburg Bridge ramp") or both."
Unfortunately driving directions are not yet available for all countries. You may want to check the following spreadsheet to see if driving directions are available for a particular location:
Google Code - Map Coverage Filtered