使用 J Query 或 JavaScript 选择 Google map 的下拉菜单更改纬度 请找到下面的代码并帮助我提前感谢您的帮助
<form>
<select class="target">
<option value="-25.363882,131.044922" selected="selected">Brazil</option>
<option value="4,3">China</option>
</select>
</form>
<div id="map_canvas"></div>
<script type="text/javascript">
$(document).ready(function () {
$('.target').change(function() {
var coordinate = $('select option:selected').val();
alert(coordinate);
// alert(google_map(coordinate));
});
});
function initialize() {
alert(coordinate);
var map_canvas = document.getElementById('map_canvas');
var map_options = {
center: new google.maps.LatLng(coordinate , coordinate1),
zoom: 4,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(map_canvas, map_options)
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
最佳答案
使用setCenter
更改 map 中心,您需要传入LatLng
对象。
$('.target').change(function() {
var coordinate = $('select option:selected').val().split(',');
map.setCenter(new google.maps.LatLng(coordinate[0], coordinate[1]));
});
从语法上来说,您需要传入纬度作为第一个参数,经度作为第二个参数。我有点假设坐标
是这样构造的。
关于javascript - 使用 JQuery 或 Javascript 选择 Google map 的下拉菜单更改纬度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22551219/