<!DOCTYPE html>
<html>
<head>
<title>Búsqueda de lugares</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
</head>
<body>
<div id="map"></div>
<!-- En la llamada al script se pasa un nuevo parámetro, para cargar la librería places-->
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDmr2x0FWWydp93kDtbO3tgadydoc9bQVc&libraries=places&callback=initMap" async defer></script>
</body>
</html>
// Se declaran las variables map e infowindow
var map;
var infowindow;
// Se inicializa el mapa mediante la función
function initMap() {
var urjc = {lat: 40.4279938, lng: -3.66781040};
map = new google.maps.Map(document.getElementById('map'), {
center: urjc,
zoom: 15
});
//Se define el valor del infowindow a través de la clase google.maps.InfoWindow
infowindow = new google.maps.InfoWindow();
//Se carga la biblioteca de sitios "places", para el subconjunto PlacesService
var service = new google.maps.places.PlacesService(map);
// con el método nearbySearch se localizan aquellos servicios que cumplan los requisitos
// indicados en los parámetros de la búsqueda
service.nearbySearch({
location: urjc,
radius: 500,
types: ['store']
}, callback);
}
function callback(results, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; 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, 'click', function() {
infowindow.setContent(place.name);
infowindow.open(map, this);
});
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.