Show Map with point Ionic 2

Asked

Viewed 308 times

1

Personal use Ionic 2 beta in a project with ts, has the coordinates of a point, I wonder how I can put the map with the current position of the user and a marker in the saved coordinates. How can I do ? Thank you

2 answers

1

To capture the current user position you can use a plugin called Geolocation. To place multiple markers (assuming that you have these positions in an array) you can place them by traversing the array and inserting them into the map at each array interaction:

let markers = arrayDePosicoes.forEach(item => {

   //cria um objeto latLng a partir de coordenadas da posição atual do array
   let currentPosition = new google.maps.LatLng(item.latitude,item.longitude);

   //cria o marcador passando a coordenada e o elemento que contém o mapa
   let marker = new google.maps.Marker({
     position: currentPostition,         
     map: map,
     title: 'Hello World!'
   });

});
  • I’ve already lat and long, I just need to put on the map ... you know how ?

1

I believe your question is quite simple to resolve. Create an object with the coordinates and pass this object to the options and then pass the options when instantiating the map on the screen. This code works for me. I hope I’ve helped!

    let myPosition = { lat: -19.911911, lng: -43.917486}

    let options = {
        zoom: 16,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        center: myPosition
    };
    let map = new google.maps.Map(document.getElementById("map"), options);
  • capture the position is not my problem, but rather display the map

Browser other questions tagged

You are not signed in. Login or sign up in order to post.