如何更改标记的位置,例如点击return
?
这是标记:
if
它在地图上显示,但如果我点击一个div我想要它会改变位置:
if not isinstance(arg, int):
return 'Bad Type' # return
else:
return old_function(arg) # return
我怎么能这样做?
答案 0 :(得分:1)
function initialize() {
var map = new google.maps.Map(
document.getElementById("map_canvas"), {
center: new google.maps.LatLng(30, 30),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var marker = new google.maps.Marker({
position: new google.maps.LatLng(30, 30),
map: map
});
$('#btn').on('click', function() {
marker.setPosition(new google.maps.LatLng(60, 60));
map.setCenter(marker.getPosition());
});
$('#btn2').on('click', function() {
marker.setPosition(new google.maps.LatLng(30, 30));
map.setCenter(marker.getPosition());
});
}
google.maps.event.addDomListener(window, "load", initialize);

html,
body,
#map_canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
#footer {
height: 25px;
width: 100%;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="btn">click me 1</div>
<div id="btn2">click me 2</div>
<div id="map_canvas"></div>
<div id="footer"></div>
&#13;