Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Request main road / curbside StreetView panoramas instead of back alleys from API

Is there a way to request main road Google StreetView panorama data instead of back alley panorama data for a given location (latitude/longitude)?

I'm using the Google Maps Javascript API to retrieve a street view panorama from a home address supplied by our users. It works quite well for most addresses I've tried, but I'm noticing a lot of properties in California also have street views for back alleys, and the API seams to be consistently returning the back alley panorama instead of the main road (front of property) panorama.

I don't want to show the user a back alley panorama of their home, but instead the main road panorama. If I lookup the same address on maps.google.com I see the front of the house, but when I request the same address through the API I get the back alley.

The process I'm currently using is:

  1. Geocode address
  2. Get panorama given the geocode location (lat/long)
  3. Compute heading and display panorama on page

Test Addresses:

  1. 325 S Peck Dr, Beverly Hills, CA, USA, 90212
  2. 333 S Rodeo Dr, Beverly Hills, CA, USA, 90212

Any ideas or suggestions would be greatly appreciated. Thanks!

like image 596
dbrown428 Avatar asked Jul 02 '15 05:07

dbrown428


People also ask

Is Street View available in Google Maps free API?

The Street View Static API is charged for each request to embed a static (non-interactive) Street View panorama. Cost starts at 0.007 USD per each (7.00 USD per 1000) with a usage limit of 30,000 maximum queries per minute.

How do I turn off Street View in Google Maps API?

Street View Map Usage You may hide this control within the map's MapOptions by setting streetViewControl to false .

How do I request Google Street View?

Google Street View FAQs While you can't request an update on Street View, you can do it on Google Earth. Visit the “Google Earth website” and click on the “location” of the map you want to get updated. Click “Feedback” from the menu (the three horizontal lines in the upper left-hand corner) and fill out the form.

How do you get a panorama on Google Maps?

Google MapsIn the lower right hand corner, you'll see the Street View icon. Select the icon and place it where you'd like to snap a 360 image within the map. Once, you set it down, you will see the 360 view.


1 Answers

Use the directions service to get directions from the desired address to itself. Use that location instead of the geocoder result for the street view location. Use the geocoder result (hopefully a ROOFTOP accuracy result) for the place to look "at".

related question: Facing the targeted building with Google StreetView Examples:

  • 325 S Peck Dr, Beverly Hills, CA, USA, 90212
  • 333 S Rodeo Dr, Beverly Hills, CA, USA, 90212

code snippet:

var sv = new google.maps.StreetViewService();
var geocoder = new google.maps.Geocoder();
var directionsService = new google.maps.DirectionsService();
var panorama;
var address = "333 S Rodeo Dr, Beverly Hills, CA, USA, 90212";
var myLatLng;

function initialize() {

  panorama = new google.maps.StreetViewPanorama(document.getElementById("pano"));

  geocoder.geocode({
    'address': address
  }, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      myLatLng = results[0].geometry.location;

      // find a Streetview location on the road
      var request = {
        origin: address,
        destination: address,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
      };
      directionsService.route(request, directionsCallback);
    } else {
      alert("Geocode was not successful for the following reason: " + status);
    }
  });
}
google.maps.event.addDomListener(window, 'load', initialize);

function processSVData(data, status) {
  if (status == google.maps.StreetViewStatus.OK) {

    panorama.setPano(data.location.pano);

    var heading = google.maps.geometry.spherical.computeHeading(data.location.latLng, myLatLng);
    panorama.setPov({
      heading: heading,
      pitch: 0,
      zoom: 1
    });
    panorama.setVisible(true);

  } else {
    alert("Street View data not found for this location.");
  }
}

function directionsCallback(response, status) {
  if (status == google.maps.DirectionsStatus.OK) {
    var latlng = response.routes[0].legs[0].start_location;
    sv.getPanoramaByLocation(latlng, 50, processSVData);
  } else {
    alert("Directions service not successfull for the following reason:" + status);
  }
}
<script src="https://maps.googleapis.com/maps/api/js?libraries=geometry&key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script>
<div id="pano" style="width: 425px; height: 400px;float:left"></div>
like image 58
geocodezip Avatar answered Sep 28 '22 19:09

geocodezip