简体   繁体   中英

Google direction api not working correctly

I am working on a java program where I use text search and directions api, but somehow api's are not working correctly in some cases.

For example: I have to search "restaurants" near Hyundai Car Center,Sector 63, Noida .

For this I have used the text search api to get the formatted address of the required restaurant. Now when I used direction api to calculate the shortest time and distance between the locations, I did not find any result.

String addressFrom = "Mother Dairy, Bhim Nagri, Hauz Khas, New Delhi, India";
String addressTo = "Hyundai Car Center,Sector 63,Noida";
String urlString = "http://maps.googleapis.com/maps/api/directions/xml?sensor=true&origin="
                + addressFrom + "&destination=" + addressTo;
System.out.println(urlString);

I am getting the following output:

http://maps.googleapis.com/maps/api/directions/xml?sensor=true&origin=Mother+Dairy%2C+Bhim+Nagri%2C+Hauz+Khas%2C+New+Delhi%2C+India&destination=Hyundai+Car+Center%2CSector+63%2CNoida
<?xml version="1.0" encoding="UTF-8"?>
<DirectionsResponse>
 <status>NOT_FOUND</status>
</DirectionsResponse>

The problem is that "Mother Dairy, Bhim Nagri, Hauz Khas, New Delhi, India" cannot be found. You can test whether the endpoints can be found by entering them (one at a time) in the Google Geocoder Sample page .

However, "Bhim Nagri, Hauz Khas, New Delhi, India" can be found, and is fairly close to where "Mother Dairy" is marked on the map.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM