<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>
如果$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>