如果您知道地址,并且 ROOFTOP 地理编码器结果可用,您可以找到道路上最近的位置,然后使用它来请求街景:
http://www.geocodezip.com/v3_Streetview_lookAtB.html?snaptoroad=5175%20Buena%20Vista%20Boulevard,%20Castle%20Rock,%20CO%2080109,%20USA
(如果您不知道地址,您可以像我在这里所做的那样对位置进行反向地理编码以获取它)
这个问题的工作示例:Using google street view with a marker, how do I point the POV at a marker?
工作小提琴
工作代码片段:
var geocoder = new google.maps.Geocoder();
var myStreetView = null;
var marker = null;
function geocodeAddress() {
var address = document.getElementById('address').value;
geocoder.geocode({
'address': address
}, function(results, status) {
//alert (results);
if (status == google.maps.GeocoderStatus.OK) {
//alert(results[0].geometry.location);
myStreetView = new google.maps.StreetViewPanorama(document.getElementById("map_canvas"));
myStreetView.setPosition(results[0].geometry.location);
google.maps.event.addListenerOnce(myStreetView, 'status_changed', function() {
var SVstatus = myStreetView.getStatus()
document.getElementById('info').innerHTML = "Street View Status="+SVstatus;
var heading = google.maps.geometry.spherical.computeHeading(myStreetView.getLocation().latLng, results[0].geometry.location);
myStreetView.setPov({
heading: heading,
pitch: 0
});
setTimeout(function() {
marker = new google.maps.Marker({
position: results[0].geometry.location,
map: myStreetView,
title: address
});
if (marker && marker.setMap) marker.setMap(myStreetView);
}, 500);
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
google.maps.event.addDomListener(document.getElementById('geoBtn'), 'click', geocodeAddress);
}
google.maps.event.addDomListener(window, 'load', geocodeAddress);
html,
body,
#map_canvas {
height: 100%;
width: 100%;
}
<script src="http://maps.google.com/maps/api/js?libraries=geometry"></script>
<input id="address" type="text" value="5175 Buena Vista Boulevard, Castle Rock, CO 80109, USA" />
<input id="geoBtn" type="button" value="Go" />
<div id="info"></div>
<div id="map_canvas"></div>