SoWhat
SoWhat

Reputation: 5622

Google maps direction renderer exact match only

I am using DirectionRenderer(gmap3) to show the user directions. The problem is it shows a match even if it cannot find an exact match. Eg: SomeFakePlace, myRealCity will match myRealCity even if it cannot match SomeFakePlace.

So it shows the directions from City's center to the place, instead. The destination is fixed(myLatLng)

I want it to return null and not show a route if cannot find one. I have decent error display to handle that.

  $("#map-canvas-single").gmap3({ 
          getroute:{
            options:{
                origin:$("#directions-from").val(),
                destination:myLatlng,
                travelMode: google.maps.DirectionsTravelMode.DRIVING
            },
            callback: function(results){
                console.log(results);
                   var point= results.routes[0].overview_path[0]
                    window.directionMarker = new google.maps.Marker({
                        position: new google.maps.LatLng(point.jb,point.kb),
                        title:$("#directions-from").val(),
                        //icon:"http://maps.google.com/mapfiles/ms/icons/<?php if($this->listing->type=="pg"):?>green<?php else: ?>purple<?php endif;?>-dot.png"

                    });
                    window.directionMarker.setMap($(this).gmap3("get"));

             if(!results)
                 noty({text:"Place not found!",type:"error"});
             else
             {
                 $(this).gmap3({
                     directionsrenderer:{
                       container: $("#directions-container"),
                          id:"directions",
                       options:{
                         directions:results,
                        suppressMarkers :true //<<Look here>>
                       } 
                     }
                   });

            }
          }
        }
      });

The code works fine and all. I think this the fault of direction renderer service, not gmaps. I am sure htere must be some parameter for an exact match

Upvotes: 3

Views: 754

Answers (1)

Jack
Jack

Reputation: 188

I'm not familiar with Google Maps API, but what I'd do is do a geocode lookup on the source address and find the lat, lng. You'll usually get coordinates with levels of confidence, so you can have a minimum threshold below which to throw an error.

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

Also, don't forget mapquest.

http://developer.mapquest.com/web/products/dev-services/geocoding-ws

Upvotes: 2

Related Questions