3
I created a project on Ionic and I would like that when the user clicked on "save location", the position from where he left the marker was saved in his user profile in firebase, however, I have no idea how to take the latitude and longitude of the marker and save in firebase, some solution???
loadMap(){
this.geolocation.getCurrentPosition().then((position)=> {
let latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); // pegando localização atual
let mapOptions = { //opções do mapa
center: latLng,
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP,
disabledZoomDoubleClick: true,
fullscreenControl: true
}
this.map = new google.maps.Map(document.getElementById('map'), mapOptions); //adicionando mapa com as opçoes
let marker = new google.maps.Marker({ //Adicionando marcador
map: this.map,
animation: google.maps.Animation.DROP,
position: latLng,
draggable: true,
});
let data = {
lat: null,
lng: null
}
google.maps.event.addListener(marker, 'click', function(event){ //Aciona quando o usuario clica no marcador
data.lat = event.latLng.lat();
data.lng = event.latLng.lng();
});
}, (error) => {
console.log(error);
});
}
addFirebase(){ //aqui é a função do botão que vai salvar a localização
}
What you’ve already done?
– DiegoAugusto
How you plan to capture the location, by marker, by address name..?
– DiegoAugusto
need to capture the location of the marker at the point the user has dragged, it is draggable
– Junior Dos Santos
Got it, could you add your map code? Just edit your question and add the code snippet
– DiegoAugusto
Okay, just a second
– Junior Dos Santos
just need the location of the marker that he dragged, stay saved in firebase, when click on the "save location" button and will call the "addFirebase()"
– Junior Dos Santos
Let’s go by parts, first you need to take the latitude and longitude and then save rs
– DiegoAugusto
OK kkk this very rs
– Junior Dos Santos
Another question, when you click it is not running the addListener function?
– DiegoAugusto
that click was just a test I did, it was the closest I got to getting the location of the marker
– Junior Dos Santos
but it was not useful because I could not use it in the "addFirebase()" that is triggered when you click the button
– Junior Dos Santos
All right, when I get home I’ll set an example for you.
– DiegoAugusto
All right, thanks bro
– Junior Dos Santos