2
votes

I try to create a show direction app. I use google map direction to draw a polyline for the route that i want. But i want to make sure that the origin address and destination address are real so can you guys show me how to that. Maybe a tool or how to catch a problem so that i can 't make a toast about the mistake input, all will fine.

1

1 Answers

0
votes

The directions API may be exactly what you need:

https://developers.google.com/maps/documentation/directions/intro

The directions API first geocodes your destination and origin to make sure there is a valid lat,lng for both. If one or both can't be geocoded you will get an error and no route will be returned. It uses the geocoding API to do this. The directions API will also return an encoded polyline for the route.

If you must perform the check before calling the directions API, You can use the geocoding API yourself on your destination and origin addresses to make sure the addresses can be properly geocoded if you wish to do so. Please see the geocoding doc here:

https://developers.google.com/maps/documentation/geocoding/start

Please note that the geocoding API is not meant to be an address validation service. It is made for giving a lat,lng for a complete, unambiguous address and vice versa. I'm just suggesting that you can use the geocoder on the origin and destination before calling the directions API if you must make sure the destination and origin can be geocoded before calling the directions API. Also, please note that even if both the destination and origin have valid geocodes, it may still be impossible to find a route between the two points with the available travel modes using the directions API.

I hope this helps!