Skip to content Skip to sidebar Skip to footer

Doing "points Of Interest Along A Route" In Google Maps

I need to allow travelers to use google maps to plot a route, and then query my database of points of interest (let's say, McDonald's locations) and then show all of these location

Solution 1:

Check this out

http://google-maps-utility-library-v3.googlecode.com/svn/tags/routeboxer/1.0/examples/routeboxer-v3.html

Here's the documentation: http://google-maps-utility-library-v3.googlecode.com/svn/tags/routeboxer/1.0/docs/examples.html

You could get the box coordinates from RouteBoxer and send that to a serverside script for processing

Solution 2:

<!DOCTYPE html><html><head><metaname="viewport"content="initial-scale=1.0, user-scalable=no"><metacharset="utf-8"><title>Polygon arrays</title><style>#map {
        height: 100%;
      }
      html, body {
        height: 100%;
        margin: 0;
        padding: 0;
      }
    </style></head><body><divid="map"></div><script>var map;
      functioninitMap() {
         map = new google.maps.Map(document.getElementById('map'), {
          center: {lat: 19.2570, lng: 72.8712},
          zoom: 10,
        });

        var directionService = new google.maps.DirectionsService();
        var directionsRenderer = new google.maps.DirectionsRenderer({ map: map }); 
        var request = {
           origin: "<?phpecho$source;?>",
          destination: "<?phpecho$destination;?>", 
          travelMode: google.maps.DirectionsTravelMode.DRIVING
        }


        directionService.route(request, function(result, status) {
        if (status == google.maps.DirectionsStatus.OK) {

            var path = result.routes[0].overview_path;

            var poly = new google.maps.Polyline({
              strokeColor: '#FF0000',
              strokeOpacity: 1.0,
              strokeWeight: 3,
             map: map,
            });
            poly.setPath(path);


            var myTollLocations = [
              <?phpisset($hello); //$hello is array which comes from databaseforeach ($helloas$key => $value) {
                ?>new google.maps.LatLng(<?phpecho$hello[$key]->latitude;?>, <?phpecho$hello[$key]->longitude;?>),
                <?php
              }
              ?>

            ];


            for (var i = 0; i < myTollLocations.length  ; i++) {
              if (google.maps.geometry.poly.isLocationOnEdge(myTollLocations[i], poly,0.005)) {
                  console.log("found");


                }else{
                  console.log("Not Found!");
                }
            };




           <?php$markersLocation =  array($source, $destination);
             foreach ($markersLocationas$key => $values) {

             ?>//Source Marker( convert address to LatLng for marker)   var geocoder = new google.maps.Geocoder();            
            geocoder.geocode( { 'address': '<?phpecho$markersLocation[$key]?>'}, function(results, status) {

                if (status == google.maps.GeocoderStatus.OK) {
                    var latitude = results[0].geometry.location.lat();
                    var longitude = results[0].geometry.location.lng();
                }

                console.log(latitude);
                console.log(longitude);

                var myLatLng = {lat: latitude, lng: longitude};



                var marker = new google.maps.Marker({
                    position: myLatLng,
                    map: map,
                    title: 'source',
                    icon: 'http://innowrap.com/clients/digitoll/ic_red_marker.png'

                });

            });


            <?php
           }
            ?>


          } else {
            alert("Directions query failed: " + status);
          }
        });


      }


    </script><scriptsrc="https://maps.googleapis.com/maps/api/js?key=ADD YOUR API KEY&libraries=geometry&callback=initMap"asyncdefer></script></body></html>

Post a Comment for "Doing "points Of Interest Along A Route" In Google Maps"