首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >要求主干道/路边StreetView全景图,而不是从API回来的小巷

要求主干道/路边StreetView全景图,而不是从API回来的小巷
EN

Stack Overflow用户
提问于 2015-07-02 05:36:32
回答 1查看 2.1K关注 0票数 6

是否有一种方法来请求主干道Google StreetView全景数据,而不是对给定位置(纬度/经度)的后巷全景数据?

我正在使用Google API从我们的用户提供的家庭地址中检索街景全景图。它对我尝试过的大多数地址都很有效,但我注意到加州的许多房产也有后巷的街景,API接缝会不断地返回后巷全景图,而不是主干道(房产前)全景图。

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

当前使用的进程是:

  1. 地码地址
  2. 获取给定地理代码位置的全景图(lat/long)
  3. 计算标题并在页面上显示全景图

测试地址:

  1. 美国加利福尼亚州贝弗利山庄S派克博士,90212
  2. 美国加利福尼亚州贝弗利山庄S博士,90212

如有任何意见或建议,将不胜感激。谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-02 13:33:04

使用“指示”服务从所需地址获取指向其自身的指示。使用该位置,而不是街头视图位置的地理编码器结果。使用地理编码器的结果(希望屋顶精确的结果)的地方看。

相关问题:使用Google StreetView面向目标建筑示例:

  • 美国加利福尼亚州贝弗利山庄S派克博士,90212
  • 美国加利福尼亚州贝弗利山庄S博士,90212

代码片段:

代码语言:javascript
运行
复制
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);
  }
}
代码语言:javascript
运行
复制
<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>

票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31176327

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档