What you need is to generate the list where you have the attributes "latitude" and "longitude". This code works, to check it, add your API KEY
$(".actualizarMapa").on("click", function() {
initMap($(this).attr("latitud"), $(this).attr("longitud"));
});
function initMap(latitud, longitud) {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 15,
center: new google.maps.LatLng(latitud,longitud)
});
var marker = new google.maps.Marker({
position: new google.maps.LatLng(latitud,longitud),
map: map,
title: 'Hello World!'
});
}
function initMapByDefault() {
var myLatLng = {lat: -8.1167518, lng: -79.0371252};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 15,
center: myLatLng
});
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: 'Hello World!'
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
</style>
<body>
<a id="ubicacionSucural1" style="cursor: pointer;" latitud="-8.1167518" longitud="-79.0371252" class="actualizarMapa">
<p>Sucursal La tiendita de Don Pepe Trujillo </p>
<p>Calle Francisco Pizarro 551 </p>
</a>
<br>
<a id="ubicacionSucural2" style="cursor: pointer;" latitud="-12.0553436" longitud="-77.063575" class="actualizarMapa">
<p>Sucursal La tiendita de Don Pepe Lima </p>
<p>Calle Francisco Pizarro 551 </p>
</a>
<div id="map"></div>
<script src="https://maps.googleapis.com/maps/api/js?key=AQUI_COLOCAS_TU_API_KEY&callback=initMapByDefault"
async defer></script>
</body>
For the solution of this question I have based myself on the example found on the official Google Maps website: link
and there is another example as the good El Asiduo
says in: link