Prueba con esto
Código HTML:
Ver original<!DOCTYPE html>
<title>Google Maps JavaScript API v3 Example: Place Search
</title>
<script src="https://maps.googleapis.com/maps/api/js?sensor=true&libraries=places"></script> <script src="http://code.jquery.com/jquery-1.7.2.min.js"></script> #map {
height: 400px;
width: 600px;
border: 1px solid #333;
margin-top: 0.6em;
}
var map;
var infowindow;
function initialize() {
var pyrmont = new google.maps.LatLng(17.562406,-99.504623);
map = new google.maps.Map(document.getElementById('map'), {
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: pyrmont,
zoom: 15
});
var request = {
location: pyrmont,
radius: 500,
};
infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.search(request, callback);
}
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
var datos = '';
for (var i = 0; i < results.length; i++) {
createMarker(results[i]);
datos += i + ' ' + results[i].name + '<br/>';
}
document.getElementById("text").innerHTML = datos;
}
}
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, 'click', function() {
infowindow.setContent(place.name);
infowindow.open(map, this);
});
}
google.maps.event.addDomListener(window, 'load', initialize);