[我正在使用javascript api在我的网站上显示地图,它可以工作,但是当我将值更改为数据库值时,它不起作用

问题描述 投票:0回答:1
<script type="text/javascript">
function my_map_add() {
var myMapCenter = new google.maps.LatLng(28.5383866, 77.34916609);
var myMapProp = {center:myMapCenter, zoom:12, scrollwheel:false, draggable:false, 
mapTypeId:google.maps.MapTypeId.ROADMAP};
var map = new google.maps.Map(document.getElementById("my_map_add"),myMapProp);
var marker = new google.maps.Marker({position:myMapCenter});
marker.setMap(map);
}
</script>

但是当我这样做时,它不起作用。$ id1和$ id2是数据库中的值

<script type="text/javascript">
function my_map_add() {
var myMapCenter = new google.maps.LatLng($id1, $id2);
var myMapProp = {center:myMapCenter, zoom:12, scrollwheel:false, draggable:false, 
mapTypeId:google.maps.MapTypeId.ROADMAP};
var map = new google.maps.Map(document.getElementById("my_map_add"),myMapProp);
var marker = new google.maps.Marker({position:myMapCenter});
marker.setMap(map);
}
</script>
javascript php html maps
1个回答
0
投票

如果$id来自PHP变量,则必须使用echo ::>

<script type="text/javascript">
function my_map_add() {
var myMapCenter = new google.maps.LatLng(<?php echo $id1.','.$id2; ?>); //here
var myMapProp = {center:myMapCenter, zoom:12, scrollwheel:false, draggable:false, 
mapTypeId:google.maps.MapTypeId.ROADMAP};
var map = new google.maps.Map(document.getElementById("my_map_add"),myMapProp);
var marker = new google.maps.Marker({position:myMapCenter});
marker.setMap(map);
}
</script>
© www.soinside.com 2019 - 2024. All rights reserved.