我希望能够使用Google Maps API v3拥有自己的“街景”按钮。单击按钮后,我希望它根据标记的纬度加载街道视图。然后,我想将按钮更改为“返回地图”,然后将再次加载默认地图视图。
单击按钮时,我试图使用getStreetView(myLatlng),但它没有加载街景,因此我在这里一定会遗漏某些东西,但似乎无法在网络上找到任何帮助。这是我的代码:-
var map;
var myLatlng = new google.maps.LatLng(42.333029,-83.04559);
/**
* The HomeControl adds a control to the map that simply
* returns the user to Chicago. This constructor takes
* the control DIV as an argument.
* @constructor
*/
function customStreetView(controlDiv, map) {
// Offset from the corner
controlDiv.style.padding = '10px';
// Create control div
var controlUI = document.createElement('div');
controlUI.innerHTML = "View on street";
controlUI.className = "google_map_button"
controlDiv.appendChild(controlUI);
// Setup the click event listener
google.maps.event.addDomListener(controlUI, 'click', function() {
var panorama = map.getStreetView(myLatlng);
if(panorama){panorama.setVisible(false);}
});
}
function initialize() {
var mapOptions = {
zoom: 17,
center: myLatlng,
panControl: true,
zoomControl: true,
mapTypeControl: false,
scaleControl: true,
streetViewControl: false,
overviewMapControl: true
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
// Set the marker
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
icon: 'images/google-map-marker.png'
});
// Create the DIV to hold the control and
// call the HomeControl() constructor passing
// in this DIV.
var homeControlDiv = document.createElement('div');
var homeControl = new customStreetView(homeControlDiv, map);
homeControlDiv.index = 1;
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(homeControlDiv);
google.maps.event.addDomListener(window, 'load', initialize);
}
</script>
有人可以帮忙吗?
谢谢
visible
为true
该position
不会通过的参数进行设置getStreetView()
时,必须设置该属性通过set
,setValues
,setPosition
或setOptions
google.maps.event.addDomListener(controlUI, 'click', function() {
map.getStreetView().setOptions({visible:true,position:myLatlng});
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句