我的代码只显示半径范围内的单个城市。 我需要显示多个城市,你可以帮助他们。我有以下代码:
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"></script>
<style>
html, body, #map_canvas { margin: 0; padding: 0; height: 100% }
</style>
<!-- CHECK ELEMENT ID also UPDATE CSS -->
<script>
var map;
var infowindow;
function initialize() {
// Center of Map
var centerLatlng = new google.maps.LatLng(33.523949, -111.903557);
// Marker Icons Declaration
// Map Options
var myOptions = {
zoom: 12,
center: centerLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
};
// Draw the map
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var marker = new google.maps.Marker({
map: map,
position: centerLatlng,
});
// Marker Icons Implementation
// Services: Places
$propertyIDs = new Array('locality');
// alert($propertyIDs.length);
// alert($propertyIDs);
if($propertyIDs.length!==0){
var request = {
location: centerLatlng,
radius: 20*1000,
types:$propertyIDs
};
// alert(request.types);
infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.search(request, callback);
}
} // function initialize()
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
console.log(results);
for (var i = 0; i < results.length; i++) {
alert(results[i]);
createMarker(results[i]);
}
}
}
function createMarker(place) {
var placeLoc = place.geometry.location;
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location,
});
google.maps.event.addListener(marker, 'mouseover', function() {
infowindow.setContent(place.name + '<br/>' + place.vicinity + '<br/><img src="' + place.icon + '">');
infowindow.open(map, this);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<html>
<body>
<div id="map_canvas"></div>
</body>
</html>
我得到了中心点标记和scottsdale城市标记但是如果我将半径改为50km(即50 * 1000)它只显示pheonix上的标记而不显示scottsdale上的标记