I'm trying to get the map to zoom in on a particular markers location when they are created in Firebase.
I already tried to use the
setZoom()
setCenter()
I'dlikeittobeontopofthecorrectlocation,forexample:IthasaMarkersfromBarraShopping,itgoesstraighttotheshoppingmall.
WhatItriedwasthefollowing:
GM.js
functioninitMap(){varmap;map=newgoogle.maps.Map(document.getElementById('map'),{center:{lat:-1.000,lng:62.000},mapTypeId:'hybrid',zoom:2,zoomControl:true,zoomControlOptions:{position:google.maps.ControlPosition.RIGHT_CENTER},streetViewControl:false,rotateControl:false,fullscreenControl:false,styles:[{"featureType": "administrative",
"elementType": "geometry",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "poi",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "road",
"elementType": "labels.icon",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "transit",
"stylers": [
{
"visibility": "off"
}
]
}
]
});
generateMarkerDBS();
searchAllMarkers(map);
}
firebase.js
function searchAllMarkers(map){
var locations = firebase.database().ref('/').child('aliansce');
locations.on('value', function(keysSnapshot){
// SE CONTER LOCAIS DA COMPANIA
// IRÁ MOSTRAR OS MAKERS NO MAPA
if(keysSnapshot.numChildren() > 0){
locations.on('child_added', function(keysSnapshot){
var markersCoordinatesNodes = firebase.database().ref('/aliansce/').child('' + keysSnapshot.key + '/marker/markerCoordinates/');
markersCoordinatesNodes.on('value', function(coordinatesSnapshot){
if((coordinatesSnapshot.val().lat == null) && (coordinatesSnapshot.val().lng == null)){
alert("LAT ou LNG NULL's no DATABASE!!");
} else {
var markersDateNodes = firebase.database().ref('/aliansce/'+ keysSnapshot.key + '/marker/markerDateCreate/').child('dateDescription');
markersDateNodes.on('value', function(dateSnapshot){
var infowindow = [];
var arrMarkers = [];
var arrMarkers = new google.maps.Marker({
position: new google.maps.LatLng(coordinatesSnapshot.val().lat,coordinatesSnapshot.val().lng),
map: map,
title: keysSnapshot.key
});
map.setZoom(15);
map.panTo(arrMarkers.position);
arrMarkers.infowindow = new google.maps.InfoWindow({
position: new google.maps.LatLng(coordinatesSnapshot.val().lat,coordinatesSnapshot.val().lng),
content:
'<div><strong>'+ keysSnapshot.key +'</strong><br></div>'+
'<div>'+ dateSnapshot.val() +'</div>',
});
arrMarkers.infowindow.open(map,arrMarkers);
arrMarkers.addListener('click', function(event,infowindow){
this.infowindow.open(map,arrMarkers);
});
});
}
});
});
} else {
alert("NÃO CONTÉM LOCAIS DA COMPANIA NO DATABASE");
}
});
}