我过去所做的就是这样。我检查 StreetViewService 在给定位置 50 米范围内是否有“全景图”。这是一些完整的示例 JS 代码,应该可以按原样工作。
<!DOCTYPE html>
<html>
<head>
<title>Streetview</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#streetView { height: 100%; width: 100%; }
</style>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript">
function createStreetMap(strMapCanvasID, intLat, intLong)
{
//create a google latLng object
var streetViewLocation = new google.maps.LatLng(intLat,intLong);
var panorama;
//once the document is loaded, see if google has a streetview image within 50 meters of the given location, and load that panorama
var sv = new google.maps.StreetViewService();
sv.getPanoramaByLocation(streetViewLocation, 50, function(data, status) {
if (status == 'OK') {
//google has a streetview image for this location, so attach it to the streetview div
var panoramaOptions = {
pano: data.location.pano,
addressControl: false,
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.SMALL
}
};
var panorama = new google.maps.StreetViewPanorama(document.getElementById(strMapCanvasID), panoramaOptions);
}
else{
//no google streetview image for this location, so hide the streetview div
$('#' + strMapCanvasID).parent().hide();
}
});
return panorama;
}
$(document).ready(function() {
var myPano = createStreetMap('streetView', 51.513016, -0.144424);
});
</script>
</head>
<body>
<div>
<h2>Street View</h2>
<div id="streetView"></div>
</div>
</body>
</html>
然后我只在 DOM 加载后才调用此函数(否则,如果尝试在函数内过早执行此操作,我会发现错误initialize
)。
$(document).ready(function() {
var myPano = createStreetMap('streetView', someLatitude, someLongitude);
});
createStreetMap
我相信 C# 而不是使用来自内部的调用,而是$(document).ready(function() { ... });
使用WebBrowser.InvokeScript方法并执行以下操作:
object[] args = {"streetView",51.513016,-0.144424};
webBrowser1.Document.InvokeScript("createStreetMap",args);
另请参阅: http: //www.codeproject.com/Tips/60924/Using-WebBrowser-Document-InvokeScript-to-mess-aro