ionic-team / ionic-native-google-maps

Google maps plugin for Ionic Native
Other
221 stars 125 forks source link

duplicate polyline of google map #234

Closed aligassan closed 4 years ago

aligassan commented 4 years ago

I'm submitting a ... (check one with "x")

If you choose 'problem or bug report', please select OS: (check one with "x")

I am trying to get latitude and longitude of flight route from data json api . While updating points of flight path using setInterval l get duplicate of flight path .

Before data refresh

https://i.stack.imgur.com/SiaE1.png enter image description here

After refresh data

https://i.imgur.com/0CDnDcD.png

my code

async ngOnInit() {
    await this.platform.ready();
    await this.loadmap()
    await this.getmarker()

}

loadmap(){
    this.map = GoogleMaps.create('map_canvas')

    if(GoogleMapsEvent.MAP_READY){

        setInterval(()=>{
            this.getmarker()

        },5)
    }
}

async getmarker() {

        this.http.get('xxxxxxxxxxxxxx=' + this.id + '', {}, {})
        .then(data => {
            console.log(data.data+'My data')

            // Track aircraft 

            for (let datas of JSON.parse(data.data).result.response.data.flight['track']) {

                this.points.push({ lng: datas.longitude, lat: datas.latitude });

            }

    ////////// aircraft Polyline path /////

    let polyline: Polyline = this.map.addPolylineSync({
            points: this.points,
            color: '#AA00FF',
            width: 4,
            geodesic: true,

        });

        });

}
wf9a5m75 commented 4 years ago

It's because you don't remove the previous polyline.

aligassan commented 4 years ago

It's because you don't remove the previous polyline. How can i remove it ? do have example ?

wf9a5m75 commented 4 years ago

Please read the documents.