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

查看:25
本文介绍了从 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)?

我正在使用 Google Maps Javascript API 从我们用户提供的家庭地址中检索街景全景图.它适用于我尝试过的大多数地址,但我注意到加利福尼亚的许多物业也有后巷的街景,并且 API 接缝始终返回后巷全景而不是主要道路(前财产)全景.

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.

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

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.

我目前使用的流程是:

  1. 地理编码地址
  2. 根据地理编码位置(纬度/经度)获取全景图
  3. 计算标题并在页面上显示全景

测试地址:

  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!

推荐答案

使用路线服务获取从所需地址到自身的路线.使用该位置而不是街景位置的地理编码器结果.使用地理编码器结果(希望是 ROOFTOP 精度结果)作为要查看的位置.

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

相关问题:用谷歌街景面对目标建筑示例:

代码片段:

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>

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

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