Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70432

How can i create a current location to auto refresh

$
0
0

@wandie wrote:

How can i create a current location to auto refresh every after like 3 seconds, this is my code for showing current location, how do i make it to auto update every after like 3 seconds

//method to get user Position
getUserPosition(){
this.options = {
enableHighAccuracy : true
};

this.geolocation.getCurrentPosition(this.options).then((pos : Geoposition) => {

    this.currentPos = pos;
    console.log(pos);
    this.addMap(pos.coords.latitude,pos.coords.longitude);

},(err : PositionError)=>{
    console.log("error : " + err.message);
});

}

//call user position when entering viewport
ionViewDidEnter(){
this.getUserPosition();
}

//create the map
addMap(lat,long){

let latLng = new google.maps.LatLng(lat, long);

let mapOptions = {
center: latLng,
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
}

this.map = new google.maps.Map(this.mapElement.nativeElement, mapOptions);
this.addMarker();

}

//adding marker position
addMarker(){

let marker = new google.maps.Marker({
map: this.map,
animation: google.maps.Animation.DROP,
position: this.map.getCenter()
});

let content = "<p>This is your current position !</p>";
let infoWindow = new google.maps.InfoWindow({
content: content
});

google.maps.event.addListener(marker, 'click', () => {
infoWindow.open(this.map, marker);
});

}

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 70432

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>