Show Map with ionic point 2

1

Personal use ionic 2 beta in a project with ts, has the cordenadas of a point, I would like to know how I can do to put the map with the current position of the user and a marker in the saved coordinates. How can I do it ? Thanks

    
asked by anonymous 21.10.2016 / 00:43

2 answers

1

To capture the user's current position you can use a plugin called Geolocation . To place multiple markers (assuming you have these positions in an array) you can place them by traversing the array and inserting on the map 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!'
   });

});
    
21.10.2016 / 22:14
1

I think your question is very simple to solve. Create an object with the coordinates and pass this object to the options and then pass the options at the time of instantiating the map on the screen. This code works for me. Hope this helps!

    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);
    
27.10.2016 / 03:12