question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't update marker position with setPosition

See original GitHub issue

I am trying to make my App auto update position of markers loading from an API. Everything is fine except that the setPosition function doesn’t move my Markers. Bellow is the last try I made, forcing the coordinates to update by 0.1 each loop:

let pos: ILatLng = {
                lat: this.me._x,
                lng: this.me._y
            }            
            let opt: MarkerOptions = {
                title: 'Testing',
                position: pos,
                icon: 'blue'
            }
            this.map.addMarker(opt).then((marker) => { 
                this.marker = marker;
            }, (error) => { 
                console.log(error); 
            });

            this.interval = setInterval(() => {
                pos.lat += 0.01;
                pos.lng += 0.01;
                if(this.marker !== undefined){                
                    this.marker.setPosition(pos);
                }                
            }, 3000);

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
shivakumar116commented, Jul 23, 2019

@artnicbr

Here is my project https://github.com/shivakumar116/Track-In Once check homepage.ts

0reactions
piyushysoftcommented, Sep 9, 2021
import {
  GoogleMaps,
  GoogleMap,
  GoogleMapsEvent,
  GoogleMapOptions,
  CameraPosition,
  MarkerOptions,
  Marker, LatLng
} from '@ionic-native/google-maps';

devices: any[] = [];
markers: any[] = [];
locations: any[] = [];
duration = 4000;
speed: any = 0;


ioReceiveLocation() {
    this.socket.on('ioReceiveLocation', (data) => {
      console.log(data);
      if (this.devices.indexOf(data.uuid) === -1) {
        this.devices.push(data.uuid);
        const indice = this.devices.indexOf(data.uuid);
        this.createMarker(data.location, indice);
      } else {
        const indice = this.devices.indexOf(data.uuid);
        this.setPositionAnimate(data.location, indice);
      }
    });
  }

createMarker(location, indice) {
    let latlng = new LatLng(location.coords.latitude, location.coords.longitude);
    let markerOptions = {
      title: 'Ionic',
      icon: 'red',
      animation: 'BOUNCE',
      position: latlng
    };
    this.markers[indice] = this.map.addMarker(markerOptions);
  }

  setPositionAnimate(location, indice) {
    let latlng = new LatLng(location.coords.latitude, location.coords.longitude);
    this.speed = location.coords.speed * 3.6;
    this.markers[indice].setPosition(latlng);
  }

this.markers[indice].setPosition(latlng) not work, not move, not animate Help-me!!!

@manuvalentim Your issue is resolved ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to update Google Maps marker position without them ...
When new data arrives, update the markers by that unique id. ... setPosition) { var planeIcon = new google.maps.Marker({ position: myLatlng ...
Read more >
Google Maps JavaScript API V3 Reference
AdvancedMarkerViewOptions interface. Properties: collisionBehavior , content , draggable , element , map , position , title , zIndex. Beta PinView class.
Read more >
Updating position for a list of markers - GIS Stack Exchange
At the gmaps script, markers are stored on an array, and then I was thinking of taking each point and using the setPoint...
Read more >
dynamically change 3 marker position on the fly - YouTube
Your browser can't play this video. ... setCenter marker. setPosition 3 locations in kathmandu music by Nishang Yonjan ...
Read more >
moving the marker to current location after data gets updated??
... current location address after moving the marker again if i click on the position data is not updating ... setPosition(place.geometry.location); } map....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found