最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Request main roadcurbside StreetView panoramas instead of back alleys from API - Stack Overflow

programmeradmin6浏览0评论

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 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!

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. 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!

Share Improve this question edited Jul 23, 2015 at 20:28 Marc M. 3,7915 gold badges35 silver badges53 bronze badges asked Jul 2, 2015 at 5:36 dbrown428dbrown428 1931 silver badge12 bronze badges 2
  • 3 You mean like this: 325 S Peck Dr, Beverly Hills, CA, USA, 90212 and this: 333 S Rodeo Dr, Beverly Hills, CA, USA, 90212 – geocodezip Commented Jul 2, 2015 at 13:30
  • Oh wow!! Exactly like that. Brilliant!! – dbrown428 Commented Jul 2, 2015 at 16:38
Add a ment  | 

1 Answer 1

Reset to default 10

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.puteHeading(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./maps/api/js?libraries=geometry&key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script>
<div id="pano" style="width: 425px; height: 400px;float:left"></div>

发布评论

评论列表(0)

  1. 暂无评论