ionic-team / ionic-native-google-maps

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

MARKER_CLICK not working #329

Closed jgm196 closed 3 years ago

jgm196 commented 3 years ago

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

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

cordova information: (run $> cordova plugin list)

com-sarriaroman-photoviewer 1.1.16 "PhotoViewer"
com.googlemaps.ios 2.6.0 "Google Maps SDK for iOS"
cordova-plugin-actionsheet 2.3.3 "ActionSheet"
cordova-plugin-add-swift-support 1.7.1 "AddSwiftSupport"
cordova-plugin-camera 4.0.3 "Camera"
cordova-plugin-device 2.0.2 "Device"
cordova-plugin-dialogs 2.0.2 "Notification"
cordova-plugin-geolocation 4.0.1 "Geolocation"
cordova-plugin-googlemaps 2.3.1 "cordova-plugin-googlemaps"
cordova-plugin-googleplus 7.0.1 "Google SignIn"
cordova-plugin-inappbrowser 4.0.1-dev "InAppBrowser"
cordova-plugin-ionic-keyboard 2.0.5 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 1.2.1 "cordova-plugin-ionic-webview"
cordova-plugin-nativegeocoder 3.1.1 "NativeGeocoder"
cordova-plugin-nativestorage 2.3.1 "NativeStorage"
cordova-plugin-network-information 2.0.1 "Network Information"
cordova-plugin-screen-orientation 3.0.1 "Screen Orientation"
cordova-plugin-splashscreen 5.0.2 "Splashscreen"
cordova-plugin-telerik-imagepicker 2.2.1 "ImagePicker"
cordova-plugin-whitelist 1.3.3 "Whitelist"

If you use @ionic-native/google-maps, please tell the package.json (only @ionic-native/core and @ionic-native/google-maps are fine mostly) "@ionic-native/core": "^4.7.0", "@ionic-native/google-maps": "^4.8.2" Current behavior: I have read all the documentation about the plugin and I could get MARKER_CLICK listener work on my project. My last test is

       this.map.addMarker({
          title:'ionic',
          icon: 'blue',
         position: {lat: ..., lng: ...},
        }).then(this.onMarkerAdded);
onMarkerAdded(marker:Marker){
  console.log(marker.getTitle());
  marker.one(GoogleMapsEvent.MARKER_CLICK).then(()=>{
    alert("Marker"+ marker.getTitle()+" clicked");
  });
}

The console.log shows propertly, but when I click the marker I get this error in console: image.

This is the full code of my loadMap function:

      loadMap() {
    this.loading.present(); 
    let mapOptions: GoogleMapOptions = {
      camera: {
         target: {
           lat: 36.8535658,
           lng: -2.4432077
         },
         zoom: 15,
         tilt: 30
       }
    };
    this.map = GoogleMaps.create('map_canvas', mapOptions);
    this.map.one(GoogleMapsEvent.MAP_READY).then(() => {
        var  i:any;  
        this.map.on(GoogleMapsEvent.MAP_CLICK).subscribe(() => {
          alert("Click!");
        });
        this.zone.run(() => {  
        for (i = 0; i < this.posiciones.length; i++) {
        let pruebapos: LatLng = new LatLng(this.posiciones[i].lat, this.posiciones[i].lon);
        this.map.addMarker({
          title:this.posiciones[i].nombre,
          icon: 'blue',
          position: pruebapos
        }).then(this.onMarkerAdded);
        this.bounds.push(pruebapos);
      }   
    });      
      let latLngBounds = new LatLngBounds(this.bounds);
      this.map.moveCamera({
        'target': latLngBounds
      });   
      this.loading.dismiss();
    }
        );   
}

I have included the MAP_CLICK event and it works nice.

Expected behavior:

Screen capture or video record:

Related code, data or error log (please format your code or data):

The person who share your project files on Github (or other git repository) is in faster lane than other people.
Please share your project files on Github or others(Bitbucket, Gitlabs...etc).
If you don't want to share your project files, please create a demo project, then share it.

Screen captures, and/or native logs(such as Logcat, xcode logs) are appreciate.

Giving much information, you are waiting time is less.
Thank you for your cooperation.
wf9a5m75 commented 3 years ago
cordova-plugin-googlemaps 2.3.1 

Because too much old

jgm196 commented 3 years ago

Does this function not work in such an old version of the plugin? the project is almost 3 years old. but I am afraid to update the plugin. What is the safest way to update it? If the update doesnt goes well, how can i come back to my older version?

wf9a5m75 commented 3 years ago

Since internal implementation is different, you need to use at least v2.6.0

I don't support old versions. Only the latest version.

If the update doesnt goes well, how can i come back to my older version?

Please make a backup before trying.

jgm196 commented 3 years ago

I have updated the plugin and now it worked as expected. I have had to modify other page with map and location of the user, but now everything works nice. Thanks for your help, your time and your plugin.