update: Map.getVisibleRegion() returns a visible region instead of latLngBounds
MODIFY
plugin.xml
plugin.xml
<?xml version='1.0' encoding='utf-8'?>
-<plugin id="cordova-plugin-googlemaps" version="2.0.0-beta2-20170516-1315" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
+<plugin id="cordova-plugin-googlemaps" version="2.0.0-beta2-20170517-2215" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>cordova-plugin-googlemaps</name>
<js-module name="BaseClass" src="www/BaseClass.js">
<runs />

MODIFY
src/android/plugin/google/maps/PluginMap.java
src/android/plugin/google/maps/PluginMap.java
@@ -2251,17 +2251,39 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
target.put("lng", position.target.longitude);
params.put("target", target);
- LatLngBounds latLngBounds = projection.getVisibleRegion().latLngBounds;
- JSONObject result = new JSONObject();
+ VisibleRegion visibleRegion = projection.getVisibleRegion();
+ LatLngBounds latLngBounds = visibleRegion.latLngBounds;
+
JSONObject northeast = new JSONObject();
- JSONObject southwest = new JSONObject();
northeast.put("lat", latLngBounds.northeast.latitude);
northeast.put("lng", latLngBounds.northeast.longitude);
+ params.put("northeast", northeast);
+
+ JSONObject southwest = new JSONObject();
southwest.put("lat", latLngBounds.southwest.latitude);
southwest.put("lng", latLngBounds.southwest.longitude);
- params.put("northeast", northeast);
params.put("southwest", southwest);
+ JSONObject nearLeft = new JSONObject();
+ nearLeft.put("lat", visibleRegion.nearLeft.latitude);
+ nearLeft.put("lng", visibleRegion.nearLeft.longitude);
+ params.put("nearLeft", nearLeft);
+
+ JSONObject nearRight = new JSONObject();
+ nearRight.put("lat", visibleRegion.nearRight.latitude);
+ nearRight.put("lng", visibleRegion.nearRight.longitude);
+ params.put("nearRight", nearRight);
+
+ JSONObject farLeft = new JSONObject();
+ farLeft.put("lat", visibleRegion.farLeft.latitude);
+ farLeft.put("lng", visibleRegion.farLeft.longitude);
+ params.put("farLeft", farLeft);
+
+ JSONObject farRight = new JSONObject();
+ farRight.put("lat", visibleRegion.farRight.latitude);
+ farRight.put("lng", visibleRegion.farRight.longitude);
+ params.put("farRight", farRight);
+
jsonStr = params.toString();
} catch (JSONException e) {
e.printStackTrace();

MODIFY
src/ios/GoogleMaps/GoogleMapsViewController.m
src/ios/GoogleMaps/GoogleMapsViewController.m
[json setObject:southwest forKey:@"southwest"];
+
+ NSMutableDictionary *farLeft = [NSMutableDictionary dictionary];
+ [farLeft setObject:[NSNumber numberWithFloat:visibleRegion.farLeft.latitude] forKey:@"lat"];
+ [farLeft setObject:[NSNumber numberWithFloat:visibleRegion.farLeft.longitude] forKey:@"lng"];
+ [json setObject:farLeft forKey:@"farLeft"];
+
+ NSMutableDictionary *farRight = [NSMutableDictionary dictionary];
+ [farRight setObject:[NSNumber numberWithFloat:visibleRegion.farRight.latitude] forKey:@"lat"];
+ [farRight setObject:[NSNumber numberWithFloat:visibleRegion.farRight.longitude] forKey:@"lng"];
+ [json setObject:farRight forKey:@"farRight"];
+
+ NSMutableDictionary *nearLeft = [NSMutableDictionary dictionary];
+ [nearLeft setObject:[NSNumber numberWithFloat:visibleRegion.nearLeft.latitude] forKey:@"lat"];
+ [nearLeft setObject:[NSNumber numberWithFloat:visibleRegion.nearLeft.longitude] forKey:@"lng"];
+ [json setObject:nearLeft forKey:@"nearLeft"];
+
+ NSMutableDictionary *nearRight = [NSMutableDictionary dictionary];
+ [nearRight setObject:[NSNumber numberWithFloat:visibleRegion.nearRight.latitude] forKey:@"lat"];
+ [nearRight setObject:[NSNumber numberWithFloat:visibleRegion.nearRight.longitude] forKey:@"lng"];
+ [json setObject:nearRight forKey:@"nearRight"];
+
+
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:json options:0 error:nil];
NSString* sourceArrayString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSString* jsString = [NSString

MODIFY
www/Map.js
www/Map.js
@@ -577,15 +577,22 @@ Map.prototype.setDiv = function(div) {
*/
Map.prototype.getVisibleRegion = function(callback) {
var self = this;
- var northeast = self.get("camera_northeast");
- var southwest = self.get("camera_southwest");
- var latLngBounds = new LatLngBounds(northeast, southwest);
+ var cameraPosition = self.get("camera");
+
+ var latLngBounds = new LatLngBounds(cameraPosition.northeast, cameraPosition.southwest);
if (typeof callback === "function") {
+ console.log("[deprecated] getVisibleRegion() is changed. Please check out the https://goo.gl/yHstHQ");
callback.call(self, latLngBounds);
}
- return latLngBounds;
+ return {
+ "latLngBounds" : latLngBounds,
+ "nearLeft": new LatLng(cameraPosition.nearLeft.lat, cameraPosition.nearLeft.lng),
+ "nearRight": new LatLng(cameraPosition.nearRight.lat, cameraPosition.nearRight.lng),
+ "farLeft": new LatLng(cameraPosition.farLeft.lat, cameraPosition.farLeft.lng),
+ "farRight": new LatLng(cameraPosition.farRight.lat, cameraPosition.farRight.lng)
+ }
};
/**
@@ -1036,9 +1043,7 @@ Map.prototype.getCameraTilt = function() {
Map.prototype.getCameraBearing = function() {
return this.get("camera_bearing");
};
-Map.prototype._onCameraEvent = function(eventName, params) {
- //var cameraPosition = new CameraPosition(params);
- var cameraPosition = params;
+Map.prototype._onCameraEvent = function(eventName, cameraPosition) {
this.set('camera', cameraPosition);
this.set('camera_target', cameraPosition.target);
this.set('camera_zoom', cameraPosition.zoom);
@@ -1046,6 +1051,10 @@ Map.prototype._onCameraEvent = function(eventName, params) {
this.set('camera_tilt', cameraPosition.viewAngle || cameraPosition.tilt);
this.set('camera_northeast', cameraPosition.northeast);
this.set('camera_southwest', cameraPosition.southwest);
+ this.set('camera_nearLeft', cameraPosition.nearLeft);
+ this.set('camera_nearRight', cameraPosition.nearRight);
+ this.set('camera_farLeft', cameraPosition.farLeft);
+ this.set('camera_farRight', cameraPosition.farRight);
this.trigger(eventName, cameraPosition, this);
};
module.exports = Map;

update: Map.getVisibleRegion() returns a visible region instead of latLngBounds