Implement the `setMyLocationButtonEnabled()` method
MODIFY
plugin.xml
plugin.xml
<?xml version='1.0' encoding='utf-8'?>
-<plugin id="cordova-plugin-googlemaps" version="2.2.0-beta-20180124-2220" 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.2.0-beta-20180125-1932" 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 />
@@ -102,9 +102,8 @@ The native map view is faster, use less network usage, display 3D views, and eve
<keywords>google,maps,geo</keywords>
<engines>
- <engine name="cordova" version=">=6.2.0" />
<engine name="cordova-android" version=">=5.1.0" />
- <engine name="cordova-ios" version=">=4.5.0" />
+ <engine name="cordova-ios" version=">=4.0.0" />
</engines>
<!-- android -->

MODIFY
src/android/plugin/google/maps/PluginGeolocation.java
src/android/plugin/google/maps/PluginGeolocation.java
@@ -177,6 +177,7 @@ public class PluginGeolocation extends CordovaPlugin {
_checkLocationSettings(isHigh, callbackContext);
} else {
Log.e(TAG, "===> googleApiClient.isConnected() is not connected");
+ googleApiClient.connect();
}
}

MODIFY
src/android/plugin/google/maps/PluginMap.java
src/android/plugin/google/maps/PluginMap.java
@@ -97,6 +97,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
private boolean isDragging = false;
//public final ConcurrentHashMap<String, Object> objects = new ConcurrentHashMap<String, Object>();
public final ObjectCache objects = new ObjectCache();
+ private View myLocationButton;
@@ -228,6 +229,23 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
@Override
public void onMapReady(GoogleMap googleMap) {
+ myLocationButton = new View(activity);
+ FrameLayout.LayoutParams lParams = new FrameLayout.LayoutParams((int)(48 * density), (int)(48 * density));
+ lParams.gravity = Gravity.RIGHT;
+ lParams.rightMargin = (int)(6 * density);
+ lParams.topMargin = (int)(6 * density);
+ lParams.leftMargin = 0;
+ myLocationButton.setClickable(true);
+ myLocationButton.setVisibility(View.GONE);
+ myLocationButton.setLayoutParams(lParams);
+ myLocationButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ PluginMap.this.onMyLocationButtonClick();
+ }
+ });
+ mapView.addView(myLocationButton);
+
map = googleMap;
projection = map.getProjection();
@@ -270,6 +288,12 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
right = (int) (padding.getInt("right") * density);
}
map.setPadding(left, top, right, bottom);
+
+ FrameLayout.LayoutParams lParams2 = (FrameLayout.LayoutParams) myLocationButton.getLayoutParams();
+ lParams2.rightMargin = right + (int)(5 * density);
+ lParams2.topMargin = top + (int)(5 * density);
+ myLocationButton.setLayoutParams(lParams2);
+
}
if (preferences.has("zoom")) {
@@ -310,22 +334,20 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
if (params.has("controls")) {
JSONObject controls = params.getJSONObject("controls");
- if (controls.has("myLocationButton")) {
- final Boolean isEnabled = controls.getBoolean("myLocationButton");
+ if (controls.has("myLocationButton") || controls.has("myLocation")) {
+ final JSONArray args = new JSONArray();
+ args.put(controls);
+
cordova.getThreadPool().submit(new Runnable() {
@Override
public void run() {
- if (isEnabled) {
try {
- JSONArray args = new JSONArray();
- args.put(isEnabled);
PluginMap.this.setMyLocationEnabled(args, callbackContext);
} catch (JSONException e) {
e.printStackTrace();
callbackContext.error(e.getMessage() + "");
}
}
- }
});
}
}
@@ -1199,6 +1221,11 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
right = (int) (padding.getInt("right") * density);
}
map.setPadding(left, top, right, bottom);
+
+ FrameLayout.LayoutParams lParams2 = (FrameLayout.LayoutParams) myLocationButton.getLayoutParams();
+ lParams2.rightMargin = right + (int)(5 * density);
+ lParams2.topMargin = top + (int)(5 * density);
+ myLocationButton.setLayoutParams(lParams2);
}
if (preferences.has("zoom")) {
@@ -1246,12 +1273,9 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
if (controls.has("mapToolbar")) {
settings.setMapToolbarEnabled(controls.getBoolean("mapToolbar"));
}
- if (controls.has("myLocationButton")) {
- boolean isEnabled = controls.getBoolean("myLocationButton");
- settings.setMyLocationButtonEnabled(isEnabled);
-
+ if (controls.has("myLocation") || controls.has("myLocationButton")) {
JSONArray args = new JSONArray();
- args.put(isEnabled);
+ args.put(controls);
PluginMap.this.setMyLocationEnabled(args, callbackContext);
} else {
callbackContext.success();
@@ -1650,6 +1674,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
}
}
+
/**
* Enable MyLocation feature if set true
* @param args
@@ -1679,22 +1704,24 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
}
}
+ JSONObject params = args.getJSONObject(0);
+ final Boolean isMyLocationButtonEnabled = params.getBoolean("myLocationButton");
+ final Boolean isMyLocationEnabled = params.getBoolean("myLocation");
- final Boolean isEnabled = args.getBoolean(0);
this.activity.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
- map.setMyLocationEnabled(isEnabled);
+ map.getUiSettings().setMyLocationButtonEnabled(isMyLocationButtonEnabled);
+ myLocationButton.setVisibility(isMyLocationButtonEnabled ? View.INVISIBLE : View.GONE);
+ map.setMyLocationEnabled(isMyLocationEnabled);
} catch (SecurityException e) {
e.printStackTrace();
}
- map.getUiSettings().setMyLocationButtonEnabled(isEnabled);
callbackContext.success();
}
});
}
-
/**
* Clear all markups
* @param args Parameters given from JavaScript side
@@ -2015,6 +2042,12 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
@Override
public void run() {
map.setPadding(left, top, right, bottom);
+
+ FrameLayout.LayoutParams lParams2 = (FrameLayout.LayoutParams) myLocationButton.getLayoutParams();
+ lParams2.rightMargin = right + (int)(5 * density);
+ lParams2.topMargin = top + (int)(5 * density);
+ myLocationButton.setLayoutParams(lParams2);
+
callbackContext.success();
}
});

MODIFY
src/android/plugin/google/maps/PluginMarker.java
src/android/plugin/google/maps/PluginMarker.java
@@ -155,7 +155,6 @@ public class PluginMarker extends MyPlugin implements MyPluginInterface {
!objectId.startsWith("marker_imageSize") &&
!objectId.startsWith("marker_icon_")) {
Marker marker = (Marker) pluginMap.objects.remove(objectId);
- marker.setIcon(null);
marker.setTag(null);
marker.remove();
marker = null;

MODIFY
src/ios/GoogleMaps/PluginMap.m
src/ios/GoogleMaps/PluginMap.m
- (void)setMyLocationEnabled:(CDVInvokedUrlCommand *)command {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
- Boolean isEnabled = [[command.arguments objectAtIndex:0] boolValue];
- self.mapCtrl.map.settings.myLocationButton = isEnabled;
- self.mapCtrl.map.myLocationEnabled = isEnabled;
+ NSDictionary *params =[command.arguments objectAtIndex:0];
+
+ self.mapCtrl.map.settings.myLocationButton = [[params valueForKey:@"myLocationButton"] boolValue];
+ self.mapCtrl.map.myLocationEnabled = [[params valueForKey:@"myLocation"] boolValue];
}];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
isEnabled = [[controls valueForKey:@"myLocationButton"] boolValue];
if (isEnabled == true) {
self.mapCtrl.map.settings.myLocationButton = YES;
- self.mapCtrl.map.myLocationEnabled = YES;
} else {
self.mapCtrl.map.settings.myLocationButton = NO;
+ }
+ }
+ //myLocation
+ if ([controls valueForKey:@"myLocation"] != nil) {
+ isEnabled = [[controls valueForKey:@"myLocation"] boolValue];
+ if (isEnabled == true) {
+ self.mapCtrl.map.myLocationEnabled = YES;
+ } else {
self.mapCtrl.map.myLocationEnabled = NO;
}
}

MODIFY
www/Map.js
www/Map.js
@@ -29,6 +29,9 @@ var Map = function(id, _exec) {
var self = this;
BaseClass.apply(self);
+ self.set("myLocation", true);
+ self.set("myLocationButton", true);
+
self.MARKERS = {};
self.OVERLAYS = {};
@@ -92,6 +95,11 @@ Map.prototype.getMap = function(mapId, div, options) {
self.set("clickable", options.clickable === false ? false : true);
self.set("visible", options.visible === false ? false : true);
+ if (options.control) {
+ this.set("myLocation", options.control.myLocation === true);
+ this.set("myLocationButton", options.control.myLocationButton === true);
+ }
+
if (!common.isDom(div)) {
self.set("visible", false);
options = div;
@@ -235,6 +243,10 @@ Map.prototype.getMap = function(mapId, div, options) {
Map.prototype.setOptions = function(options) {
options = options || {};
+ if (options.control) {
+ this.set("myLocation", options.control.myLocation === true);
+ this.set("myLocationButton", options.control.myLocationButton === true);
+ }
if (options.camera) {
if (options.camera.latLng) {
options.camera.target = options.camera.latLng;
@@ -515,13 +527,30 @@ Map.prototype.moveCamera = function(cameraPosition, callback) {
};
+Map.prototype.setMyLocationButtonEnabled = function(enabled) {
+ enabled = common.parseBoolean(enabled);
+ this.set("myLocationButton", enabled);
+ exec.call(this, null, this.errorHandler, this.id, 'setMyLocationEnabled', [{
+ myLocationButton: enabled,
+ myLocation: this.get("myLocation")
+ }], {
+ sync: true
+ });
+ return this;
+};
+
Map.prototype.setMyLocationEnabled = function(enabled) {
enabled = common.parseBoolean(enabled);
- exec.call(this, null, this.errorHandler, this.id, 'setMyLocationEnabled', [enabled], {
+ this.set("myLocation", enabled);
+ exec.call(this, null, this.errorHandler, this.id, 'setMyLocationEnabled', [{
+ myLocationButton: this.get("myLocationButton"),
+ myLocation: enabled
+ }], {
sync: true
});
return this;
};
+
Map.prototype.setIndoorEnabled = function(enabled) {
enabled = common.parseBoolean(enabled);
exec.call(this, null, this.errorHandler, this.id, 'setIndoorEnabled', [enabled]);

MODIFY
www/event.js
www/event.js
@@ -19,7 +19,6 @@ module.exports = {
INFO_LONG_CLICK: 'info_long_click',
INFO_CLOSE: 'info_close',
INFO_OPEN: 'info_open',
- CLUSTER_CLICK: 'cluster_click',
MARKER_CLICK: 'marker_click',
MARKER_DRAG: 'marker_drag',
MARKER_DRAG_START: 'marker_drag_start',

Implement the `setMyLocationButtonEnabled()` method