diff --git a/README.md b/README.md index 268f3fff3..62530b995 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Cordova GoogleMaps plugin for Android, iOS and Browser v2.7.0 +# Cordova GoogleMaps plugin for Android, iOS and Browser v2.7.1 | Download | Build test (multiple_maps branch)| |----------|---------------------------| @@ -37,81 +37,11 @@ ## Quick install - - *Stable version(npm)* - ``` - $> cordova plugin add cordova-plugin-googlemaps - ``` - - - *Development version(beta version)* - ``` - $> cordova plugin add https://github.com/mapsplugin/cordova-plugin-googlemaps#multiple_maps - ``` - -## PhoneGap Build settings - - ```xml - - - - - - ``` - -## Install optional variables - - - ![](https://raw.githubusercontent.com/mapsplugin/cordova-plugin-googlemaps/master/images/icon-android.png) **PLAY_SERVICES_VERSION = (15.0.1)**
- The Google Play Services SDK version. - _You need to specify the same version number with all other plugins._ - Check out the latest version [here](https://developers.google.com/android/guides/releases). - - - ![](https://raw.githubusercontent.com/mapsplugin/cordova-plugin-googlemaps/master/images/icon-android.png) **ANDROID_SUPPORT_V4_VERSION = (27.1.1)**
- This plugin requires the Android support library v4. - _The minimum version is 24.1.0._ - Check out the latest version [here](https://developer.android.com/topic/libraries/support-library/revisions.html). - - - ![](https://raw.githubusercontent.com/mapsplugin/cordova-plugin-googlemaps/master/images/icon-ios.png) **LOCATION_WHEN_IN_USE_DESCRIPTION**
- This message is displayed when your application requests **LOCATION PERMISSION for only necessary times**. - - - ![](https://raw.githubusercontent.com/mapsplugin/cordova-plugin-googlemaps/master/images/icon-ios.png) **LOCATION_ALWAYS_USAGE_DESCRIPTION**
- This message is displayed when your application requests **LOCATION PERMISSION for always**. - ---------------------------------------------------------------------------------------------------------- - -## Browser platform - - We support browser platform now! - You can develop your application with browser, then run it! - At the end of development, you can upload the html files to your server, or run it on Android or iOS devices. - - ``` - $> cordova run browser - ``` - - If you use [ionic framework](https://ionicframework.com/), it supports `live-reload`. - - ``` - $> ionic cordova run browser -l - ``` - - If you want to use `live-reload`, but you don't want to use other framework or without framework, - [cordova-plugin-browsersync](https://www.npmjs.com/package/cordova-plugin-browsersync) is useful. - ``` - $> cordova plugin add cordova-plugin-browsersync - - $> cordova run (browser/android/ios) -- --live-reload + $> cordova plugin add cordova-plugin-googlemaps ``` - -### API key (Android and iOS platforms) - - As of v2.6.0, you need to specify your API keys in `config.xml` file instead of `--variable`. - This allows you to change your API keys for anytime without reinstallation. - - Please pay attention the variable names are changed. +Then set your Google Maps API keys into your `config.xml` (Android / iOS). ```xml @@ -120,11 +50,7 @@ ``` -### API key (Browser platform) - - In the browser platform, the maps plugin uses [Google Maps JavaScript API v3](https://developers.google.com/maps/documentation/javascript/) - - You need to set **two API keys for Google Maps JavaScript API v3**. +For browser platform, ```js // If your app runs this program on browser, @@ -136,7 +62,7 @@ // plugin.google.maps.environment.setEnv({ 'API_KEY_FOR_BROWSER_RELEASE': '(YOUR_API_KEY_IS_HERE)', - 'API_KEY_FOR_BROWSER_DEBUG': '' + 'API_KEY_FOR_BROWSER_DEBUG': '' // optional }); // Create a Google Maps native view under the map_canvas div. @@ -144,54 +70,36 @@ ``` -### Why **two API keys**? - - `JavaScript` code is `text code`. Even if you do obfuscation, it's still readable finally. - In order to protect your API key, you need to set `Key restriction` for these keys. - - ![](https://raw.githubusercontent.com/mapsplugin/cordova-plugin-googlemaps/master/images/api_key_restrictions.png) +## PhoneGap Build settings - If you don't set API key, the maps plugin still work with `development mode`. + ```xml + - ```js - plugin.google.maps.environment.setEnv({ - 'API_KEY_FOR_BROWSER_RELEASE': '(YOUR_API_KEY_IS_HERE)', - 'API_KEY_FOR_BROWSER_DEBUG': '' // If key is empty or unset, - // the maps plugin runs under the development mode. - }); + + + ``` - - -### Which browser supported? - - Modern browsers should work without any problem. - - ![](https://raw.githubusercontent.com/mapsplugin/cordova-plugin-googlemaps/master/images/modern_browsers.png) - - Internet Explorer 11 might work. We don't confirm all features, but basic features work. - -### Behavior differences - `Google Maps JavaScript API v3` is completely different ecosystem with `Google Maps Android API` and `Google Maps SDK for iOS`. +## Install optional variables (config.xml) - `Google Maps JavaScript API v3` : - - **can't** draw 3D building, - - **does't work** if offline, - - **can't** map rotation, - - etc... - - In the browser platform, the maps plugin works almost the same behaviors as native platforms(Android, and iOS), - but not exactly the same behaviors. - So don't expect too much. + - ![](https://raw.githubusercontent.com/mapsplugin/cordova-plugin-googlemaps/master/images/icon-android.png) **GOOGLE_MAPS_PLAY_SERVICES_VERSION = (18.+)**
+ The Google Play Services SDK version. + _You need to specify the same version number with all other plugins._ + Check out the latest version [here](https://developers.google.com/android/guides/releases). -### Touch mechanism difference + - ![](https://raw.githubusercontent.com/mapsplugin/cordova-plugin-googlemaps/master/images/icon-android.png) **ANDROID_SUPPORT_V4_VERSION = (27.1.1)**
+ This plugin requires the Android support library v4. + _The minimum version is 24.1.0._ + Check out the latest version [here](https://developer.android.com/topic/libraries/support-library/revisions.html). - As you may know, [this plugin displays native Google Maps view under the browser in Android and iOS](#how-does-this-plugin-work-android-ios). - However this plugin displays as `normal HTML element` in browser platform. + - ![](https://raw.githubusercontent.com/mapsplugin/cordova-plugin-googlemaps/master/images/icon-ios.png) **LOCATION_WHEN_IN_USE_DESCRIPTION**
+ This message is displayed when your application requests **LOCATION PERMISSION for only necessary times**. - Because of this, touch behavior is different. - The maps plugin does not hook the touch position, do not set `background: transparent`, ... etc. - But if you use this plugin as normal behavior, you don't need to consider about this. + - ![](https://raw.githubusercontent.com/mapsplugin/cordova-plugin-googlemaps/master/images/icon-ios.png) **LOCATION_ALWAYS_USAGE_DESCRIPTION**
+ This message is displayed when your application requests **LOCATION PERMISSION for always**. --------------------------------------------------------------------------------------------------------- @@ -204,8 +112,13 @@ --------------------------------------------------------------------------------------------------------- ## Release Notes + + - **v2.7.1** + - Fix: (iOS) UiWebView references present in v2.7.0 + - **v2.7.0** - Re-adoption: cordova-plugin-googlemaps-sdk dependency + - Important update: No longer support `UIWebView` on iOS. `WKWebView` only. - Fix: (iOS) Can't load image files from local host on ionic 4 / 5 - Update: (Android) prevent null pointer error in AsyncLoadImage.java - Fix: Css animation interference when call setDiv and there is a push/pop page @@ -225,22 +138,9 @@ - Remove promise-7.0.4-min.js.map - Fix: (iOS) bug fix: App crashes if "bearing" property is "" - Fix: HTMLColor2RGBA() converts to incorrect value - - Fix: (Android) Can't load marker image from the Ineternet - - - **v2.6.2** - - Fix: (Android) build error - - - **v2.6.1** - - Fix: (Android) Conflicting with `OneSignal-Cordova-SDK` - - Fix: (iOS) App crashes when marker url isn't valid. - - - **v2.6.0** - - Fix: Can not install to Cordova 9.0 project - - Fix: (Android) `ConcurrentModificationException` error at `onStop` - - Fix: (Android) Polygon becomes visible when you run `setPoints()` to invisible polygon - - Fix: (Android/iOS) TileOverlay does not work when your app runs on `file:` protocol with ionic. - - Update: (iOS) Specify the Google Maps SDK version as `=> 3.1.0`. Please use `cordova-ios@5.0.0` or above, otherwise modify `platform/ios/Podfile`. - - Add: (Android/iOS) API Key mechanism + - Fix: (Android) Can't load marker image from the Internet + - many bug fixes... + --------------------------------------------------------------------------------------------------------- diff --git a/a.patch b/a.patch new file mode 100644 index 000000000..003ba98b4 --- /dev/null +++ b/a.patch @@ -0,0 +1,278 @@ +diff --git a/src/ios/GoogleMaps/PluginMap.m b/src/ios/GoogleMaps/PluginMap.m +index 31605c94..3080fea3 100644 +--- a/src/ios/GoogleMaps/PluginMap.m ++++ b/src/ios/GoogleMaps/PluginMap.m +@@ -667,7 +667,7 @@ + } + + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; +- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; ++ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; + } + +diff --git a/src/ios/GoogleMaps/PluginMarker.m b/src/ios/GoogleMaps/PluginMarker.m +index f06e4c65..77b4fb3c 100644 +--- a/src/ios/GoogleMaps/PluginMarker.m ++++ b/src/ios/GoogleMaps/PluginMarker.m +@@ -73,7 +73,7 @@ + [createResult setObject:markerId forKey:@"__pgmId"]; + + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ +- CDVCommandDelegateImpl *cmdDelegate = (CDVCommandDelegateImpl *)self.commandDelegate; ++ __weak __auto_type weakSelf = self; + [self _create:markerId markerOptions:json callbackBlock:^(BOOL successed, id result) { + CDVPluginResult* pluginResult; + +@@ -93,7 +93,7 @@ + + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:createResult ]; + } +- [cmdDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; ++ [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; + + }]; +@@ -255,7 +255,7 @@ + } + + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; +- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; ++ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; + }]; + } +@@ -270,7 +270,7 @@ + self.mapCtrl.map.selectedMarker = nil; + self.mapCtrl.activeMarker = nil; + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; +- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; ++ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; + }]; + } +@@ -295,7 +295,7 @@ + [json setObject:longitude forKey:@"lng"]; + + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:json]; +- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; ++ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; + } + +@@ -319,7 +319,7 @@ + + + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; +- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; ++ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; + }]; + } +@@ -338,7 +338,7 @@ + marker.snippet = [command.arguments objectAtIndex:1]; + + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; +- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; ++ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; + }]; + } +@@ -358,7 +358,7 @@ + marker = nil; + + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; +- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; ++ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; + }]; + } +@@ -424,7 +424,7 @@ + } + + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; +- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; ++ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; + } + +@@ -450,7 +450,7 @@ + } else { + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR]; + } +- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; ++ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; + + }]; +@@ -470,7 +470,7 @@ + marker.opacity = [[command.arguments objectAtIndex:1] floatValue]; + + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; +- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; ++ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; + }]; + } +@@ -488,7 +488,7 @@ + marker.zIndex = [[command.arguments objectAtIndex:1] intValue]; + + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; +- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; ++ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; + }]; + } +@@ -507,7 +507,7 @@ + [marker setDraggable:isEnabled]; + + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; +- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; ++ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; + }]; + } +@@ -530,7 +530,7 @@ + NSLog(@"--->propertyId = %@", propertyId); + + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; +- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; ++ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; + } + +@@ -560,7 +560,7 @@ + [self.mapCtrl.objects setObject:properties forKey:propertyId]; + + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; +- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; ++ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; + }]; + } +@@ -582,7 +582,7 @@ + [marker setPosition:position]; + + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; +- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; ++ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; + }]; + } +@@ -601,7 +601,7 @@ + [marker setFlat: isFlat]; + + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; +- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; ++ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; + }]; + } +@@ -645,7 +645,7 @@ + [iconProperty setObject:[rgbColor parsePluginColor] forKey:@"iconColor"]; + } + +- CDVCommandDelegateImpl *cmdDelegate = (CDVCommandDelegateImpl *)self.commandDelegate; ++ __weak __auto_type weakSelf = self; + [self setIcon_:marker iconProperty:iconProperty callbackBlock:^(BOOL successed, id resultObj) { + CDVPluginResult* pluginResult; + if (successed == NO) { +@@ -653,7 +653,7 @@ + } else { + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; + } +- [cmdDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; ++ [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; + }]; + } +@@ -671,7 +671,7 @@ + [marker setRotation:degrees]; + + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; +- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; ++ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; + }]; + } +@@ -686,11 +686,11 @@ + GMSMarker *marker = [self.mapCtrl.objects objectForKey:markerId]; + + NSString *animation = [command.arguments objectAtIndex:1]; +- CDVCommandDelegateImpl *cmdDelegate = (CDVCommandDelegateImpl *)self.commandDelegate; ++ __weak __auto_type weakSelf = self; + + [self setMarkerAnimation_:animation marker:marker callbackBlock:^(void) { + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; +- [cmdDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; ++ [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; + }]; + }]; +diff --git a/src/ios/GoogleMaps/PluginMarkerCluster.m b/src/ios/GoogleMaps/PluginMarkerCluster.m +index cbf706ff..a7d61ca3 100644 +--- a/src/ios/GoogleMaps/PluginMarkerCluster.m ++++ b/src/ios/GoogleMaps/PluginMarkerCluster.m +@@ -453,7 +453,7 @@ const int GEOCELL_GRID_SIZE = 4; + - (void) endRedraw:(CDVInvokedUrlCommand*)command { + NSLog(@"--->allResults = %@", self.allResults); + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:self.allResults]; +- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; ++ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + } + + - (void) deleteProcess:(NSDictionary *) params clusterId:(NSString *)clusterId{ +diff --git a/src/ios/GoogleMaps/PluginUtil.h b/src/ios/GoogleMaps/PluginUtil.h +index d7454edf..d9fc5b72 100644 +--- a/src/ios/GoogleMaps/PluginUtil.h ++++ b/src/ios/GoogleMaps/PluginUtil.h +@@ -20,7 +20,6 @@ + #import "IPluginProtocol.h" + #import "PluginViewController.h" + #import +-#import + + typedef void (^MYCompletionHandler)(NSError *error); + +@@ -49,10 +48,6 @@ typedef void (^MYCompletionHandler)(NSError *error); + - (UIImage *)resize:(CGFloat)width height:(CGFloat)height; + @end + +-@interface CDVCommandDelegateImpl (GoogleMapsPlugin) +-- (void)hookSendPluginResult:(CDVPluginResult*)result callbackId:(NSString*)callbackId; +-@end +- + // + // animationDidStop for group animation + // http://stackoverflow.com/a/28051909/697856 +diff --git a/src/ios/GoogleMaps/PluginUtil.m b/src/ios/GoogleMaps/PluginUtil.m +index b2b283d9..096cc861 100644 +--- a/src/ios/GoogleMaps/PluginUtil.m ++++ b/src/ios/GoogleMaps/PluginUtil.m +@@ -107,26 +107,6 @@ + + @end + +- +-/* +-@implementation CDVCommandDelegateImpl (GoogleMapsPlugin) +- +-- (void)hookSendPluginResult:(CDVPluginResult*)result callbackId:(NSString*)callbackId { +- +- NSRange pos = [callbackId rangeOfString:@"://"]; +- if (pos.location == NSNotFound) { +- [self sendPluginResult:result callbackId:callbackId]; +- } else { +- NSArray *tmp = [callbackId componentsSeparatedByString:@"://"]; +- NSString *pluginName = [tmp objectAtIndex:0]; +- CDVPlugin *plugin = [self getCommandInstance:pluginName]; +- [plugin onHookedPluginResult:result callbackId:callbackId]; +- } +- +-} +-@end +-*/ +- + static char CAAnimationGroupBlockKey; + @implementation CAAnimationGroup (Blocks) + diff --git a/package.json b/package.json index 6c03090e7..bc6c54e48 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-googlemaps", - "version": "2.7.0-20200330-2338", + "version": "2.7.1", "description": "Google Maps native SDK for Android and iOS, and Google Maps JavaScript API v3 for browser.", "cordova": { "id": "cordova-plugin-googlemaps", diff --git a/plugin.xml b/plugin.xml index 4d0024f79..1a2c801c5 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + cordova-plugin-googlemaps diff --git a/src/android/frameworks/pgm-custom.gradle b/src/android/frameworks/pgm-custom.gradle index 0144d229d..e33b83361 100644 --- a/src/android/frameworks/pgm-custom.gradle +++ b/src/android/frameworks/pgm-custom.gradle @@ -39,7 +39,7 @@ android { Properties props = new Properties() def isKeyFound = 0 def useBetaSdk = 0 - props.setProperty("GOOGLE_MAPS_PLAY_SERVICES_VERSION", "16.0.0"); + props.setProperty("GOOGLE_MAPS_PLAY_SERVICES_VERSION", "18.+"); props.setProperty("ANDROID_SUPPORT_V4_VERSION", "27.1.1"); props.setProperty("GOOGLE_MAPS_ANDROID_SDK", ""); diff --git a/src/android/plugin/google/maps/CordovaGoogleMaps.java b/src/android/plugin/google/maps/CordovaGoogleMaps.java index 7e965dcee..b487a4194 100644 --- a/src/android/plugin/google/maps/CordovaGoogleMaps.java +++ b/src/android/plugin/google/maps/CordovaGoogleMaps.java @@ -22,9 +22,13 @@ import android.view.ViewGroup; import android.view.ViewTreeObserver; +import androidx.annotation.NonNull; + import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.maps.MapsInitializer; +import com.google.android.gms.maps.MapsInitializer.Renderer; +import com.google.android.gms.maps.OnMapsSdkInitializedCallback; import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaInterface; @@ -45,7 +49,7 @@ import java.util.Set; @SuppressWarnings("deprecation") -public class CordovaGoogleMaps extends CordovaPlugin implements ViewTreeObserver.OnScrollChangedListener{ +public class CordovaGoogleMaps extends CordovaPlugin implements ViewTreeObserver.OnScrollChangedListener, OnMapsSdkInitializedCallback { private final String TAG = "GoogleMapsPlugin"; private Activity activity; public ViewGroup root; @@ -69,6 +73,8 @@ public void initialize(final CordovaInterface cordova, final CordovaWebView webV pluginManager = webView.getPluginManager(); + CordovaGoogleMaps that = this; + cordova.getActivity().runOnUiThread(new Runnable() { @SuppressLint("NewApi") public void run() { @@ -202,8 +208,7 @@ public void onClick(DialogInterface dialog,int id) { //------------------------------ if (!initialized) { try { - MapsInitializer.initialize(cordova.getActivity()); - initialized = true; + MapsInitializer.initialize(cordova.getActivity(), Renderer.LATEST, that); } catch (Exception e) { e.printStackTrace(); } @@ -211,8 +216,19 @@ public void onClick(DialogInterface dialog,int id) { } }); + } - + @Override + public void onMapsSdkInitialized(@NonNull Renderer renderer) { + initialized = true; + switch (renderer) { + case LATEST: + Log.d(TAG, "The latest version of the renderer is used"); + break; + case LEGACY: + Log.d(TAG, "The legacy version of the renderer is used"); + break; + } } @Override @@ -448,15 +464,13 @@ public void getMap(final JSONArray args, final CallbackContext callbackContext) //------------------------------------------ JSONObject meta = args.getJSONObject(0); String mapId = meta.getString("__pgmId"); - PluginMap pluginMap = new PluginMap(); - pluginMap.privateInitialize(mapId, cordova, webView, null); - pluginMap.initialize(cordova, webView); - pluginMap.mapCtrl = CordovaGoogleMaps.this; - pluginMap.self = pluginMap; + PluginMap pluginMap = new PluginMap(); PluginEntry pluginEntry = new PluginEntry(mapId, pluginMap); pluginManager.addService(pluginEntry); + pluginMap.mapCtrl = CordovaGoogleMaps.this; + pluginMap.self = pluginMap; pluginMap.getMap(args, callbackContext); } @@ -470,14 +484,13 @@ public void getPanorama(final JSONArray args, final CallbackContext callbackCont String mapId = meta.getString("__pgmId"); Log.d(TAG, "---> mapId = " + mapId); PluginStreetViewPanorama pluginStreetView = new PluginStreetViewPanorama(); - pluginStreetView.privateInitialize(mapId, cordova, webView, null); - pluginStreetView.initialize(cordova, webView); - pluginStreetView.mapCtrl = CordovaGoogleMaps.this; - pluginStreetView.self = pluginStreetView; PluginEntry pluginEntry = new PluginEntry(mapId, pluginStreetView); pluginManager.addService(pluginEntry); + pluginStreetView.mapCtrl = CordovaGoogleMaps.this; + pluginStreetView.self = pluginStreetView; + pluginStreetView.getPanorama(args, callbackContext); } diff --git a/src/android/plugin/google/maps/PluginMap.java b/src/android/plugin/google/maps/PluginMap.java index a3d379f0e..3d1cf72b2 100644 --- a/src/android/plugin/google/maps/PluginMap.java +++ b/src/android/plugin/google/maps/PluginMap.java @@ -613,9 +613,6 @@ public synchronized void loadPlugin(final JSONArray args, final CallbackContext plugins.put(pluginName, pluginEntry); mapCtrl.pluginManager.addService(pluginEntry); - plugin.privateInitialize(pluginName, cordova, webView, null); - - plugin.initialize(cordova, webView); ((MyPluginInterface)plugin).setPluginMap(PluginMap.this); MyPlugin myPlugin = (MyPlugin) plugin; myPlugin.self = (MyPlugin)plugin; @@ -666,12 +663,9 @@ public void create(final JSONArray args, final CallbackContext callbackContext) pluginMap = PluginMap.this; pluginMap.mapCtrl.pluginManager.addService(pluginEntry); - plugin.privateInitialize(className, cordova, webView, null); - plugin.initialize(cordova, webView); ((MyPluginInterface)plugin).setPluginMap(PluginMap.this); pluginEntry.plugin.execute("create", args, callbackContext); - } catch (Exception e) { e.printStackTrace(); } diff --git a/src/ios/GoogleMaps/PluginMap.m b/src/ios/GoogleMaps/PluginMap.m index 31605c94c..3080fea3c 100644 --- a/src/ios/GoogleMaps/PluginMap.m +++ b/src/ios/GoogleMaps/PluginMap.m @@ -667,7 +667,7 @@ - (void)setActiveMarkerId:(CDVInvokedUrlCommand*)command { } CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; } diff --git a/src/ios/GoogleMaps/PluginMarker.m b/src/ios/GoogleMaps/PluginMarker.m index f06e4c659..77b4fb3cd 100644 --- a/src/ios/GoogleMaps/PluginMarker.m +++ b/src/ios/GoogleMaps/PluginMarker.m @@ -73,7 +73,7 @@ -(void)create:(CDVInvokedUrlCommand *)command [createResult setObject:markerId forKey:@"__pgmId"]; [[NSOperationQueue mainQueue] addOperationWithBlock:^{ - CDVCommandDelegateImpl *cmdDelegate = (CDVCommandDelegateImpl *)self.commandDelegate; + __weak __auto_type weakSelf = self; [self _create:markerId markerOptions:json callbackBlock:^(BOOL successed, id result) { CDVPluginResult* pluginResult; @@ -93,7 +93,7 @@ -(void)create:(CDVInvokedUrlCommand *)command pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:createResult ]; } - [cmdDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; }]; @@ -255,7 +255,7 @@ -(void)showInfoWindow:(CDVInvokedUrlCommand *)command } CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; }]; } @@ -270,7 +270,7 @@ -(void)hideInfoWindow:(CDVInvokedUrlCommand *)command self.mapCtrl.map.selectedMarker = nil; self.mapCtrl.activeMarker = nil; CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; }]; } @@ -295,7 +295,7 @@ -(void)getPosition:(CDVInvokedUrlCommand *)command [json setObject:longitude forKey:@"lng"]; CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:json]; - [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; } @@ -319,7 +319,7 @@ -(void)setTitle:(CDVInvokedUrlCommand *)command CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; }]; } @@ -338,7 +338,7 @@ -(void)setSnippet:(CDVInvokedUrlCommand *)command marker.snippet = [command.arguments objectAtIndex:1]; CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; }]; } @@ -358,7 +358,7 @@ -(void)remove:(CDVInvokedUrlCommand *)command marker = nil; CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; }]; } @@ -424,7 +424,7 @@ -(void)setIconAnchor:(CDVInvokedUrlCommand *)command } CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; } @@ -450,7 +450,7 @@ -(void)setInfoWindowAnchor:(CDVInvokedUrlCommand *)command } else { pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR]; } - [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; }]; @@ -470,7 +470,7 @@ -(void)setOpacity:(CDVInvokedUrlCommand *)command marker.opacity = [[command.arguments objectAtIndex:1] floatValue]; CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; }]; } @@ -488,7 +488,7 @@ -(void)setZIndex:(CDVInvokedUrlCommand *)command marker.zIndex = [[command.arguments objectAtIndex:1] intValue]; CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; }]; } @@ -507,7 +507,7 @@ -(void)setDraggable:(CDVInvokedUrlCommand *)command [marker setDraggable:isEnabled]; CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; }]; } @@ -530,7 +530,7 @@ -(void)setDisableAutoPan:(CDVInvokedUrlCommand *)command NSLog(@"--->propertyId = %@", propertyId); CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; } @@ -560,7 +560,7 @@ -(void)setVisible:(CDVInvokedUrlCommand *)command [self.mapCtrl.objects setObject:properties forKey:propertyId]; CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; }]; } @@ -582,7 +582,7 @@ -(void)setPosition:(CDVInvokedUrlCommand *)command [marker setPosition:position]; CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; }]; } @@ -601,7 +601,7 @@ -(void)setFlat:(CDVInvokedUrlCommand *)command [marker setFlat: isFlat]; CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; }]; } @@ -645,7 +645,7 @@ -(void)setIcon:(CDVInvokedUrlCommand *)command [iconProperty setObject:[rgbColor parsePluginColor] forKey:@"iconColor"]; } - CDVCommandDelegateImpl *cmdDelegate = (CDVCommandDelegateImpl *)self.commandDelegate; + __weak __auto_type weakSelf = self; [self setIcon_:marker iconProperty:iconProperty callbackBlock:^(BOOL successed, id resultObj) { CDVPluginResult* pluginResult; if (successed == NO) { @@ -653,7 +653,7 @@ -(void)setIcon:(CDVInvokedUrlCommand *)command } else { pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; } - [cmdDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; }]; } @@ -671,7 +671,7 @@ -(void)setRotation:(CDVInvokedUrlCommand *)command [marker setRotation:degrees]; CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; }]; } @@ -686,11 +686,11 @@ -(void)setAnimation:(CDVInvokedUrlCommand *)command GMSMarker *marker = [self.mapCtrl.objects objectForKey:markerId]; NSString *animation = [command.arguments objectAtIndex:1]; - CDVCommandDelegateImpl *cmdDelegate = (CDVCommandDelegateImpl *)self.commandDelegate; + __weak __auto_type weakSelf = self; [self setMarkerAnimation_:animation marker:marker callbackBlock:^(void) { CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - [cmdDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; }]; }]; diff --git a/src/ios/GoogleMaps/PluginMarkerCluster.m b/src/ios/GoogleMaps/PluginMarkerCluster.m index cbf706ff4..a7d61ca37 100644 --- a/src/ios/GoogleMaps/PluginMarkerCluster.m +++ b/src/ios/GoogleMaps/PluginMarkerCluster.m @@ -453,7 +453,7 @@ - (void)redrawClusters:(CDVInvokedUrlCommand*)command { - (void) endRedraw:(CDVInvokedUrlCommand*)command { NSLog(@"--->allResults = %@", self.allResults); CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:self.allResults]; - [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } - (void) deleteProcess:(NSDictionary *) params clusterId:(NSString *)clusterId{ diff --git a/src/ios/GoogleMaps/PluginUtil.h b/src/ios/GoogleMaps/PluginUtil.h index d7454edfa..d9fc5b720 100644 --- a/src/ios/GoogleMaps/PluginUtil.h +++ b/src/ios/GoogleMaps/PluginUtil.h @@ -20,7 +20,6 @@ #import "IPluginProtocol.h" #import "PluginViewController.h" #import -#import typedef void (^MYCompletionHandler)(NSError *error); @@ -49,10 +48,6 @@ typedef void (^MYCompletionHandler)(NSError *error); - (UIImage *)resize:(CGFloat)width height:(CGFloat)height; @end -@interface CDVCommandDelegateImpl (GoogleMapsPlugin) -- (void)hookSendPluginResult:(CDVPluginResult*)result callbackId:(NSString*)callbackId; -@end - // // animationDidStop for group animation // http://stackoverflow.com/a/28051909/697856 diff --git a/src/ios/GoogleMaps/PluginUtil.m b/src/ios/GoogleMaps/PluginUtil.m index b2b283d92..096cc8616 100644 --- a/src/ios/GoogleMaps/PluginUtil.m +++ b/src/ios/GoogleMaps/PluginUtil.m @@ -107,26 +107,6 @@ -(UIImage *)resize:(CGFloat)width height:(CGFloat)height { @end - -/* -@implementation CDVCommandDelegateImpl (GoogleMapsPlugin) - -- (void)hookSendPluginResult:(CDVPluginResult*)result callbackId:(NSString*)callbackId { - - NSRange pos = [callbackId rangeOfString:@"://"]; - if (pos.location == NSNotFound) { - [self sendPluginResult:result callbackId:callbackId]; - } else { - NSArray *tmp = [callbackId componentsSeparatedByString:@"://"]; - NSString *pluginName = [tmp objectAtIndex:0]; - CDVPlugin *plugin = [self getCommandInstance:pluginName]; - [plugin onHookedPluginResult:result callbackId:callbackId]; - } - -} -@end -*/ - static char CAAnimationGroupBlockKey; @implementation CAAnimationGroup (Blocks)