dbr*_*428 6 javascript google-maps google-maps-api-3 google-street-view google-places-api
有没有办法请求主要道路Google StreetView全景数据而不是给定位置(纬度/经度)的后巷全景数据?
我正在使用Google Maps Javascript API从我们的用户提供的家庭地址中检索街景全景图.它适用于我尝试过的大多数地址,但我注意到加利福尼亚州的很多房产也有后巷的街景,而且API接缝始终返回后巷而不是主要道路(前面)财产)全景.
我不想向用户显示他们家的后巷全景,而是主要道路全景.如果我在maps.google.com上查找相同的地址,我会看到房子的正面,但是当我通过API请求相同的地址时,我会看到后面的小巷.
我目前使用的流程是:
测试地址:
任何想法或建议将不胜感激.谢谢!
使用路线服务获取从所需地址到自身的路线.使用该位置而不是街道视图位置的地理编码器结果.使用地理编码器结果(希望ROOFTOP精度结果)使该地方看起来"at".
相关问题:使用Google StreetView 示例面向目标大楼:
代码段:
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);
}
}Run Code Online (Sandbox Code Playgroud)
<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>Run Code Online (Sandbox Code Playgroud)