May 28, 2012

Google Maps v.3 - routeplanner bug

I noticed a little bug in class google.maps.DirectionsService.
In Google Maps Javascript API V3 Reference we can read this about destination (and about origin) property:

"Location of destination. This can be specified as either a string to be geocoded or a LatLng. Required."

But be careful! If you give coordinates in string the finally route will contains some differences from expected route. My suggestion is next to avoid this problem:

aMatches = sDestination.match(/[a-z]*/i);
if(!aMatches.length || (aMatches.length==1 && aMatches[0]=="")) { // no letters in sDestination => this contains only coordinates!
  var a = sDestination.split(",");
  var oDestination = new google.maps.LatLng(1.0*a[0], 1.0*a[1]);

var request = {
  destination: oDestination ? oDestination : sDestination,

1 comment:

  1. Yeah, they always keep changing something and sometimes we get things like this one.

    Thanks for your post, helped me to resolve a problem that has suddenly appeared in my application due to this little bug.