Search code examples
google-mapstypescriptionic-frameworkgeolocation

Getting data from different method on typescript ionic 2+


tryGeolocation(){
this.loading.present();
this.clearMarkers();//remove previous markers

this.geolocation.getCurrentPosition().then((resp) => {
  let pos = {
    lat: resp.coords.latitude,
    lng: resp.coords.longitude
  };
  let marker = new google.maps.Marker({
    position: pos,
    map: this.map,
    title: 'I am here!'
  });
  this.markers.push(marker);
  this.map.setCenter(pos);
  this.loading.dismiss();

}).catch((error) => {
  console.log('Error getting location', error);
  this.loading.dismiss();
}); }

i want to get the lat and lng data from geolocation and want put that data to this method.

openModal() {
const modal = this.modalCtrl.create('ModalPage');
modal.present(); }

how? #im beginer in programing


Solution

  • You have to pass like

    const modal = this.modalCtrl.create('ModalPage',{lat:72.33,lng:22.54});
    

    In next page need to get like below

    constructor(params: NavParams) 
    {
        console.log('lat', params.get('lat'));
        console.log('lng', params.get('lng'));
    }
    

    For more info please check

    https://ionicframework.com/docs/api/components/modal/ModalController/