Get Location After Drag Marker in Google Maps... i Want Updated Lat Long After Drag & Drop ... Thanks in Advanced... This is My Code


#1
this.map.addMarker({
                  title: 'Ionic',
                  icon: 'blue',
                  animation: 'DROP',
                  draggable:true,
                  position: {
                    lat: lat1,
                    lng: lng1
                  }
                })
                .then(marker => {
                  marker.on(GoogleMapsEvent.MARKER_DRAG_END)
                    .subscribe(() => {
                      marker.getCurrentPosition().then((resp) => {

                           alert(resp);

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

              });

Problem :
Uncaught TypeError: marker.getCurrentPosition is not a function
at SafeSubscriber._next (main.js:815)
at SafeSubscriber.__tryOrUnsub (vendor.js:38438)
at SafeSubscriber.next (vendor.js:38385)
at Subscriber._next (vendor.js:38325)
at Subscriber.next (vendor.js:38289)
at Marker.trigger (plugins/cordova-plugin-googlemaps/www/BaseClass.js:62)
at Map._onMarkerEvent (plugins/cordova-plugin-googlemaps/www/Map.js:1129)
at Map.nativeCallback (plugins/cordova-plugin-googlemaps/www/googlemaps-cdv-plugin.js:690)
at Object.fireDocumentEvent (cordova.js:235)
at :1:28


Get Location (latitude and Longitude) After Drag Marker in Geo Location using Ionic 3?
#2

i Got The Answer My Self :slight_smile:


this.map.one(GoogleMapsEvent.MAP_READY)
              .then(() => {
                console.log('Map is ready!');
        
                this.map.addMarker({
                  title: 'Ionic',
                  icon: 'blue',
                  animation: 'DROP',
                  draggable:true,
                  position: {
                    lat: lat1,
                    lng: lng1
                  }
                })
                .then(marker => {
                  marker.on(GoogleMapsEvent.MARKER_DRAG_END)
                    .subscribe(() => {
                      
                      this.markerlatlong = marker.getPosition();

                      localStorage.setItem("latt1",this.markerlatlong.lat);
                      localStorage.setItem("long1",this.markerlatlong.lng);

                      this.http.get('API URL').map(res => res.json()).subscribe(data => {
                        console.log(data);
                      });
                       
                    });
                });
                
              });

:sunglasses:


#3

Thanks it worked for me too! :smiley:


#4

Thanks :slight_smile:


#5

That’s the correct solution & worked for me!


#6

Can you please share the full code And let know which plugin you are using I could not find any plugin called google map in Ionic documentation just found geolocation and others…


#7

#8

I think your Problem Solved … :slight_smile:


#9

Not Totally but I have found alternative method. So currently I am sticking with that.later I will update my code,


#10

this code working on gmpas native?


#11

can you share it? someone might need it