我有一个 php 中的城市列表,例如:
$cities = array(0=>"Absecon,NJ",1=>"Alamogordo,NJ",2=>"Atlantic city,NJ....);
我必须在地图上显示我所有的城市,如果我没有纬度和经度,可以吗?
我以这种方式初始化地图:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?key=MY_API_KEY&sensor=true">
</script>
<script type="text/javascript">
function initialize() {
var countries = '<?php echo json_enconde($cities);?>';
var mapOptions = {
center: new google.maps.LatLng(-34.397, 150.644),
zoom: 2,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),mapOptions);
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>