请求主要道路/路边StreetView全景,而不是从API返回小巷 [英] Request main road / curbside StreetView panoramas instead of back alleys from API

查看:115
本文介绍了请求主要道路/路边StreetView全景,而不是从API返回小巷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以请求主街道Google StreetView全景数据,而不是指定位置(经度/纬度)的后巷全景数据?



我正在使用Google Maps JavaScript API可从我们用户提供的家庭地址中检索街景全景图。它对我尝试过的大多数地址都很好,但我注意到加利福尼亚的很多房产也有后街小巷的街景,API接缝一直返回后巷而不是主路(前)b
$ b

我不想向用户展示他们家的后巷全景图,而是显示主要道路全景图。如果我在maps.google.com上查找同一个地址,我会看到房子的前面,但是当我通过API请求相同的地址时,我会找到后面的小巷。



我目前使用的流程是:


  1. 地理编码地址
  2. 获取全景图给定的地理编码位置(纬度/经度)

  3. 计算页面上的标题和显示全景

测试地址


    <325>美国加利福尼亚州贝弗利山325 Peck Dr 90212
  1. 333 S Rodeo Dr,Beverly Hills,CA,USA,90212



  2. 任何想法或建议将不胜感激。感谢!

    解决方案

    使用路线服务从所需地址获取路线。使用该位置代替街景视图位置的地理编码结果。使用地理编码器结果(希望得到ROOFTOP准确性结果)来查找at。


    示例:




    程式码片段

    <

      var sv = 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; //找到一个Streetview位置在路上var request = {origin:address,destination:address,travelMode:google.maps.DirectionsTravelMode.DRIVING}; directionsService.route(request,directionsCallback);} else {alert(Geocode由于以下原因不成功: + status);}});} google.maps.event.addDomListener(window,'load',initialize);函数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(真); } else {alert(找不到这个位置的街景数据。); }}函数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(方向服务不成功,原因如下:+ status); }}  

    < script src =https:// maps.googleapis.com/maps/api/js?libraries=geometry\"> ;</script><div id =panostyle =width:425px; height:400px; float:left>< / div>


    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!

    解决方案

    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:

    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"></script>
    <div id="pano" style="width: 425px; height: 400px;float:left"></div>

    这篇关于请求主要道路/路边StreetView全景,而不是从API返回小巷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆