Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with marker.getposition() in ionic 2 #1567

Closed
veder2431 opened this issue Jul 17, 2017 · 13 comments
Closed

Problem with marker.getposition() in ionic 2 #1567

veder2431 opened this issue Jul 17, 2017 · 13 comments

Comments

@veder2431
Copy link

veder2431 commented Jul 17, 2017

I am unable to get the coordinates of the marker once i move it around the map:
I am using:
"@ionic-native/geolocation": "^4.0.0", "@ionic-native/google-maps": "^4.0.0",

i am using the next fuction to initialize the marker:

 position: string = "";
  const GOOGLE:LatLng =  new LatLng(21.1213285,-86.9193511);
  loadMap() {
        
    let element: HTMLElement = document.getElementById("map");

    this.map = this.googleMaps.create(element);

    this.map.one(GoogleMapsEvent.MAP_READY).then(
      () => {
        this.presentToast("Mapa listo");

        let markerOptions: MarkerOptions = {
          position: GOOGLE,
          title: 'My position',
          snippet: "Soprendente",
          draggable: true
        };
        this.map.addMarker(markerOptions).then((maker: Marker) => {
          maker.showInfoWindow();
          maker.addEventListener(GoogleMapsEvent.MARKER_DRAG_END).subscribe((some: any) => {

            maker.getPosition().then((lt) => {
              this.position = lt.lat.toString() + " " + lt.lng.toString();

            }).catch(err => {
              this.presentToast("Error: " + err.toString());
            });

          }, (err) => {
            this.presentToast("Error: " + err.toString());
          });
        }).catch((err) => {
          this.presentToast("Error: " + err.toString());
        });

        this.map.animateCamera({
          target: GOOGLE,
          zoom: 16,
          duration: 4000
        });
      }
    ).catch((err) => {
      this.presentToast("error: " + err);
    });
  }

In my promises I don't get any errors, but I don't get the new position of the marker either

@wf9a5m75
Copy link
Member

I'm not familiar with ionic, but I think

maker.getPosition().then((lt) => {
              this.position = lt.lat.toString() + " " + lt.lng.toString();

is wrong.

let lt = maker.getPosition();
this.position = lt.lat.toString() + " " + lt.lng.toString();

@veder2431
Copy link
Author

Unfortunately it did not help, I get this error: Property 'lat' does not existe on type 'Promise'

@wf9a5m75
Copy link
Member

Um. The ionic wrapper is wrong.
https://github.com/ionic-team/ionic-native/blob/master/src/%40ionic-native/plugins/google-maps/index.ts#L1462-L1463

This plugin returns the position value as synchronize.

Marker.prototype.getPosition = function() {
var position = this.get('position');
if (!(position instanceof LatLng)) {
return new LatLng(position.lat, position.lng);
}
return position;
};

@veder2431
Copy link
Author

Thanks for your help! I'm gonna check this issue in the ionic native git

@wf9a5m75
Copy link
Member

I sent a pull request.

danielsogl/awesome-cordova-plugins#1815

@veder2431
Copy link
Author

I have question, with the pull request everything should work fine right?

@wf9a5m75
Copy link
Member

I think so, but I'm not familiar with ionic. I haven't tested it. Please test it, and please let me know if there are any problems.

@veder2431
Copy link
Author

The problem continue, I don't getPosition() of marker.

@wf9a5m75
Copy link
Member

Yes, pull request is not accepted yet.
danielsogl/awesome-cordova-plugins#1815

@wf9a5m75
Copy link
Member

I have been still waiting the ionic team merge the pull request for some reason.

@wf9a5m75
Copy link
Member

The pull request has been accepted. Please reinstall the plugin.

@veder2431
Copy link
Author

thanks very much, it works correctly.

@wf9a5m75
Copy link
Member

Sounds good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants