Ionic-native googlemaps zoom_changed event


#1

I’ve noticed that ionic-native googlemaps seems to be missing the zoom_changed event, if I try binding an on() to the map on the string “zoom_changed” nothing happens either, for example:

map.on('zoom_changed').toPromise().then(function(){
console.log("we have zoomed!");
})

Any thoughts?

Edit: aaaah, looks like I should be using GoogleMapsEvent.CAMERA_CHANGE, but it still doesn’t seem to do anything?


#2

The answer is:

this.map.on(GoogleMapsEvent.CAMERA_CHANGE).subscribe(data => {console.log(data);});

which returns a CameraPosition object:

CameraPosition {zoom: 14.15488052368164, tilt: 0, target: Object, bearing: 0, hashCode: -1384107267…}

which you can then compare the zoom level number.


#3

Do you know if there is an event for bounds_changed?


#4

hmm, well, following the same principle apparently CameraPosition also returns a “target”… see here

So I don’t know if there is a way of forcing it to return latlngbounds that you could compare???

Just thinking out loud here…


#5

Yes it returns lat and lng.But i need something like this:

(this is the sdk javascript way)

google.maps.event.addListener(map, "bounds_changed", function () {
       let bounds = map.getBounds();
       let NE = bounds.getNorthEast();
       let SW = bounds.getSouthWest();
       parameters.NELat = NE.lat();
       parameters.NELng = NE.lng();
       parameters.SWLat = SW.lat();
        parameters.SWLng = SW.lng();
})

I dont know if there is a way to force it in the native way the object says :
target?: LatLng | LatLngBounds | LatLng[];

so it can return a latlngBounds but i dont know how


#6

Just trying to see if there’s any options, and unfortunately it’s not showing much, so I don’t know why the typescript specifies several types for “target”.

So if we follow the trail, we start in the ionic-native typescript which shows the getCameraPosition function being mapped here…

but notice no parameters :frowning: so what is that a property of? GoogleMap…

so if we hop, skip and jump over to the underlying plugin, I’m looking at android here just for example:

the only place where you might get a clue in the code also seems to show no parameters:

https://github.com/mapsplugin/cordova-plugin-googlemaps/blob/master/src/android/plugin/google/maps/GoogleMaps.java#L907

So, once again, we can see how the “map” object is of type GoogleMap in the java:

https://github.com/mapsplugin/cordova-plugin-googlemaps/blob/master/src/android/plugin/google/maps/GoogleMaps.java#L148

which is in this package:

https://github.com/mapsplugin/cordova-plugin-googlemaps/blob/master/src/android/plugin/google/maps/GoogleMaps.java#L56

So, carrying on on to the java reference documentation we find the object here, and inside that is the native getCameraPosition() which also offers no clues… even the accompanying documentation here appears to be doing an excellent chocolate fireguard impression :frowning:

In conclusion shrug :neutral_face:


#7

Thanks for your research it looks pretty convincent what you say, but it has to be someone who can get it works the bounds with native map :confused:


#8

I found it . This method returns the bounds:

map.getVisibleRegion().then((data) => {
    
})

#9

So I guess if you combine the camera change event with getting the visible region that will work for you? It’s not quite as elegant as just subscribing to the event, but should work…


#10

Anybody know how to detect and fire google native map boundChange event or is there a event to detect zoom change?

Now I am using CAMERA_MOVE_END to detect boundChange and using MAP_DRAG_END to detect map dragged, when zoom map is ok, it only fire the CAMERA_MOVE_END event, but when drag maps, it fire both event which I don’t want to , I only want to fire drag event.

Anyone knows how to do that, thanks in advance.


#11

Second post of the topic (above) explains how to detect zoom change, is that any good to you?


#12

Hi , thanks for your reply.

I know how to detect zoom change using ‘CARMER_MOVE_XXX’, my issue is I don’t want to fire this kinds of event when drag the map, because , when dragging the map, there is actually no zoom change.