Any way to distinguish a building from a road in Google Maps?

So, if I have a common GPS Lat / Lng point, can I say yes, this moment is in the building, or is this moment located on the road on which the car can travel?

+5
source share
2 answers

I don’t think you can determine if a point is a road or a building exclusively with Google Maps data. For this, I think you will need an additional data source.

However, you can determine if a point is expensive using the Snap point to street method .

Google Maps API v3 Haversine, ( ) .

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example: Directions Simple</title>
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">

rad = function(x) {return x*Math.PI/180;}

distHaversine = function(p1, p2) {
  var R = 6371; // earth mean radius in km
  var dLat  = rad(p2.lat() - p1.lat());
  var dLong = rad(p2.lng() - p1.lng());

  var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
          Math.cos(rad(p1.lat())) * Math.cos(rad(p2.lat())) * Math.sin(dLong/2) * Math.sin(dLong/2);
  var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
  var d = R * c;

  return d.toFixed(3);
}

  var dirn = new google.maps.DirectionsService();
  var map;

  function initialize() {
    var center = new google.maps.LatLng(53.7877, -2.9832);
    var myOptions = {
      zoom:15,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      center: center
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    google.maps.event.addListener(map, "click", function(event) {
        // == When the user clicks on a the map, get directiobns from that point to itself ==
        var request = {
            origin: event.latLng,
            destination: event.latLng,
            travelMode: google.maps.DirectionsTravelMode.DRIVING
        };
        dirn.route(request, function(response, status) {
          if (status == google.maps.DirectionsStatus.OK) {
                if(response.routes && response.routes.length > 0){
                    route = response.routes[0];
                    if(route.overview_path && route.overview_path.length > 0){
                        pos = route.overview_path[0];
                        new google.maps.Marker({
                              position: pos,
                              map: map
                        });
                        alert(distHaversine(request.origin, pos));
                    }
                }
          }
        });
    });
  }




</script>
</head>
<body onload="initialize()">
<div id="map_canvas"></div>
</body>
</html>

, .

+4

All Articles