Javascript 在引导转盘幻灯片上移动谷歌地图标记
我正在尝试移动引导转盘幻灯片更改上的标记。我已成功生成带有标记的映射,并成功绑定幻灯片以调用函数。因此,当用户滑过地址时,谷歌地图应该显示该特定位置的标记。以下是我尝试过的:Javascript 在引导转盘幻灯片上移动谷歌地图标记,javascript,jquery,twitter-bootstrap,google-maps,google-maps-api-3,Javascript,Jquery,Twitter Bootstrap,Google Maps,Google Maps Api 3,我正在尝试移动引导转盘幻灯片更改上的标记。我已成功生成带有标记的映射,并成功绑定幻灯片以调用函数。因此,当用户滑过地址时,谷歌地图应该显示该特定位置的标记。以下是我尝试过的: <script type="text/javascript" > google.maps.event.addDomListener(window, 'load', myMap); function myMap() { var mapProp = {
<script type="text/javascript" >
google.maps.event.addDomListener(window, 'load', myMap);
function myMap() {
var mapProp = {
center:new google.maps.LatLng(-27.4698,153.0251),
zoom:11,
styles: [{featureType:"landscape",stylers:[{saturation:-100},{lightness:65},{visibility:"on"}]},{featureType:"poi",stylers:[{saturation:-100},{lightness:51},{visibility:"simplified"}]},{featureType:"road.highway",stylers:[{saturation:-100},
{visibility:"simplified"}]},{featureType:"road.arterial",stylers:[{saturation:-100},{lightness:30},{visibility:"on"}]},{featureType:"road.local",stylers:[{saturation:-100},{lightness:40},{visibility:"on"}]},{featureType:"transit",stylers:[{saturation:-100},
{visibility:"simplified"}]},{featureType:"administrative.province",stylers:[{visibility:"off"}]/**/},{featureType:"administrative.locality",stylers:[{visibility:"off"}]},{featureType:"administrative.neighborhood",stylers:[{visibility:"on"}
]/**/},{featureType:"water",elementType:"labels",stylers:[{visibility:"on"},{lightness:-25},{saturation:-100}]},{featureType:"water",elementType:"geometry",stylers:[{hue:"#ffff00"},{lightness:-25},{saturation:-97}]}]
};
var turbot = new google.maps.LatLng(-27.456730,153.029497);
var marker = new google.maps.Marker({
position:turbot,
animation:google.maps.Animation.BOUNCE,
icon: 'images/marker.png'
});
var map = new google.maps.Map(document.getElementById("map"),mapProp);
marker.setMap(map);
}
function updateMarker( map, marker ) {
marker.setPosition( new google.maps.LatLng( -33.8688, 151.2093 ) );
map.panTo( new google.maps.LatLng( -33.8688, 151.2093 ) );
}
</script>
但是看起来,updateMarker()
不知道map和marker对象。它说:
***Uncaught TypeError: Cannot read property 'setPosition' of undefined
有什么帮助吗?我确信我在错误的地方声明了该函数。您忘记将
map
和marker
参数传递给updateMarker
函数,请提供任何帮助
下面是一个修改后的示例,演示如何将标记位置更新为旋转木马幻灯片上的位置
google.maps.event.addDomListener(窗口'load',initMap);
函数initMap(){
变量位置=[
{“lat”:40.7055646,“lng”:-74.1184291},
{“lat”:37.7576948,“液化天然气”:-122.4727052}
];
var mapProps={
缩放:4
};
var map=new google.maps.map(document.getElementById(“map”),mapProps);
var marker=new google.maps.marker({
动画:google.maps.animation.BOUNCE
});
marker.setMap(map);
updateMarker(地图、标记、位置[0]);
$('#myCarousel').bind('slide.bs.carousel',函数(e){
var slidedX=$(e.relatedTarget).index();
updateMarker(地图、标记、位置[SlideDX]);
});
}
功能更新标记器(地图、标记、位置){
marker.setPosition(新的google.maps.LatLng(pos.lat,pos.lng));
map.panTo(marker.getPosition());
}
.item{
高度:90px;
}
旋转木马{
高度:60px;
}
#地图{
高度:240px;
}
纽约
旧金山
调用updateMarker
时,将一些值传递给参数“marker”?
***Uncaught TypeError: Cannot read property 'setPosition' of undefined