Skip to content

Commit e0efbb5

Browse files
author
vpatel
committed
Fix build errors caused with cordova-ios@7 due to CDVCommandDel.
Cherry pick of all code in remote PR: mapsplugin#2927.
1 parent bdb7af4 commit e0efbb5

File tree

9 files changed

+57
-73
lines changed

9 files changed

+57
-73
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ For browser platform,
8585

8686
## Install optional variables (config.xml)
8787

88-
- ![](https://raw.githubusercontent.com/mapsplugin/cordova-plugin-googlemaps/master/images/icon-android.png) **GOOGLE_MAPS_PLAY_SERVICES_VERSION = (16.0.1)**<br>
88+
- ![](https://raw.githubusercontent.com/mapsplugin/cordova-plugin-googlemaps/master/images/icon-android.png) **GOOGLE_MAPS_PLAY_SERVICES_VERSION = (18.+)**<br>
8989
The Google Play Services SDK version.
9090
_You need to specify the same version number with all other plugins._
9191
Check out the latest version [here](https://developers.google.com/android/guides/releases).

src/android/frameworks/pgm-custom.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ android {
3939
Properties props = new Properties()
4040
def isKeyFound = 0
4141
def useBetaSdk = 0
42-
props.setProperty("GOOGLE_MAPS_PLAY_SERVICES_VERSION", "16.0.0");
42+
props.setProperty("GOOGLE_MAPS_PLAY_SERVICES_VERSION", "18.+");
4343
props.setProperty("ANDROID_SUPPORT_V4_VERSION", "27.1.1");
4444
props.setProperty("GOOGLE_MAPS_ANDROID_SDK", "");
4545

src/android/plugin/google/maps/CordovaGoogleMaps.java

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@
2222
import android.view.ViewGroup;
2323
import android.view.ViewTreeObserver;
2424

25+
import androidx.annotation.NonNull;
26+
2527
import com.google.android.gms.common.ConnectionResult;
2628
import com.google.android.gms.common.GooglePlayServicesUtil;
2729
import com.google.android.gms.maps.MapsInitializer;
30+
import com.google.android.gms.maps.MapsInitializer.Renderer;
31+
import com.google.android.gms.maps.OnMapsSdkInitializedCallback;
2832

2933
import org.apache.cordova.CallbackContext;
3034
import org.apache.cordova.CordovaInterface;
@@ -44,8 +48,10 @@
4448
import java.util.LinkedHashMap;
4549
import java.util.Set;
4650

51+
import javax.swing.Renderer;
52+
4753
@SuppressWarnings("deprecation")
48-
public class CordovaGoogleMaps extends CordovaPlugin implements ViewTreeObserver.OnScrollChangedListener{
54+
public class CordovaGoogleMaps extends CordovaPlugin implements ViewTreeObserver.OnScrollChangedListener, OnMapsSdkInitializedCallback{
4955
private final String TAG = "GoogleMapsPlugin";
5056
private Activity activity;
5157
public ViewGroup root;
@@ -69,6 +75,8 @@ public void initialize(final CordovaInterface cordova, final CordovaWebView webV
6975

7076
pluginManager = webView.getPluginManager();
7177

78+
CordovaGoogleMaps that = this;
79+
7280
cordova.getActivity().runOnUiThread(new Runnable() {
7381
@SuppressLint("NewApi")
7482
public void run() {
@@ -202,17 +210,27 @@ public void onClick(DialogInterface dialog,int id) {
202210
//------------------------------
203211
if (!initialized) {
204212
try {
205-
MapsInitializer.initialize(cordova.getActivity());
206-
initialized = true;
213+
MapsInitializer.initialize(cordova.getActivity(), Renderer.LATEST, that);
207214
} catch (Exception e) {
208215
e.printStackTrace();
209216
}
210217
}
211218

212219
}
213220
});
221+
}
214222

215-
223+
@Override
224+
public void onMapsSdkInitialized(@NonNull Renderer renderer) {
225+
initialized = true;
226+
switch (renderer) {
227+
case LATEST:
228+
Log.d(TAG, "The latest version of the renderer is used");
229+
break;
230+
case LEGACY:
231+
Log.d(TAG, "The legacy version of the renderer is used");
232+
break;
233+
}
216234
}
217235

218236
@Override
@@ -448,15 +466,13 @@ public void getMap(final JSONArray args, final CallbackContext callbackContext)
448466
//------------------------------------------
449467
JSONObject meta = args.getJSONObject(0);
450468
String mapId = meta.getString("__pgmId");
469+
451470
PluginMap pluginMap = new PluginMap();
452-
pluginMap.privateInitialize(mapId, cordova, webView, null);
453-
pluginMap.initialize(cordova, webView);
454-
pluginMap.mapCtrl = CordovaGoogleMaps.this;
455-
pluginMap.self = pluginMap;
456-
457471
PluginEntry pluginEntry = new PluginEntry(mapId, pluginMap);
458472
pluginManager.addService(pluginEntry);
459473

474+
pluginMap.mapCtrl = CordovaGoogleMaps.this;
475+
pluginMap.self = pluginMap;
460476
pluginMap.getMap(args, callbackContext);
461477
}
462478

@@ -470,14 +486,13 @@ public void getPanorama(final JSONArray args, final CallbackContext callbackCont
470486
String mapId = meta.getString("__pgmId");
471487
Log.d(TAG, "---> mapId = " + mapId);
472488
PluginStreetViewPanorama pluginStreetView = new PluginStreetViewPanorama();
473-
pluginStreetView.privateInitialize(mapId, cordova, webView, null);
474-
pluginStreetView.initialize(cordova, webView);
475-
pluginStreetView.mapCtrl = CordovaGoogleMaps.this;
476-
pluginStreetView.self = pluginStreetView;
477-
489+
478490
PluginEntry pluginEntry = new PluginEntry(mapId, pluginStreetView);
479491
pluginManager.addService(pluginEntry);
480492

493+
pluginStreetView.mapCtrl = CordovaGoogleMaps.this;
494+
pluginStreetView.self = pluginStreetView;
495+
481496
pluginStreetView.getPanorama(args, callbackContext);
482497
}
483498

src/android/plugin/google/maps/PluginMap.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -612,10 +612,7 @@ public synchronized void loadPlugin(final JSONArray args, final CallbackContext
612612
PluginEntry pluginEntry = new PluginEntry(pluginName, plugin);
613613
plugins.put(pluginName, pluginEntry);
614614
mapCtrl.pluginManager.addService(pluginEntry);
615-
616-
plugin.privateInitialize(pluginName, cordova, webView, null);
617-
618-
plugin.initialize(cordova, webView);
615+
619616
((MyPluginInterface)plugin).setPluginMap(PluginMap.this);
620617
MyPlugin myPlugin = (MyPlugin) plugin;
621618
myPlugin.self = (MyPlugin)plugin;
@@ -665,13 +662,10 @@ public void create(final JSONArray args, final CallbackContext callbackContext)
665662
plugins.put(className, pluginEntry);
666663
pluginMap = PluginMap.this;
667664
pluginMap.mapCtrl.pluginManager.addService(pluginEntry);
668-
669-
plugin.privateInitialize(className, cordova, webView, null);
670-
plugin.initialize(cordova, webView);
665+
671666
((MyPluginInterface)plugin).setPluginMap(PluginMap.this);
672667
pluginEntry.plugin.execute("create", args, callbackContext);
673668

674-
675669
} catch (Exception e) {
676670
e.printStackTrace();
677671
}

src/ios/GoogleMaps/PluginMap.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ - (void)setActiveMarkerId:(CDVInvokedUrlCommand*)command {
667667
}
668668

669669
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
670-
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
670+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
671671
}];
672672
}
673673

src/ios/GoogleMaps/PluginMarker.m

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ -(void)create:(CDVInvokedUrlCommand *)command
7373
[createResult setObject:markerId forKey:@"__pgmId"];
7474

7575
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
76-
CDVCommandDelegateImpl *cmdDelegate = (CDVCommandDelegateImpl *)self.commandDelegate;
76+
__weak __auto_type weakSelf = self;
7777
[self _create:markerId markerOptions:json callbackBlock:^(BOOL successed, id result) {
7878
CDVPluginResult* pluginResult;
7979

@@ -93,7 +93,7 @@ -(void)create:(CDVInvokedUrlCommand *)command
9393

9494
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:createResult ];
9595
}
96-
[cmdDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
96+
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
9797
}];
9898

9999
}];
@@ -255,7 +255,7 @@ -(void)showInfoWindow:(CDVInvokedUrlCommand *)command
255255
}
256256

257257
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
258-
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
258+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
259259
}];
260260
}];
261261
}
@@ -270,7 +270,7 @@ -(void)hideInfoWindow:(CDVInvokedUrlCommand *)command
270270
self.mapCtrl.map.selectedMarker = nil;
271271
self.mapCtrl.activeMarker = nil;
272272
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
273-
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
273+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
274274
}];
275275
}];
276276
}
@@ -295,7 +295,7 @@ -(void)getPosition:(CDVInvokedUrlCommand *)command
295295
[json setObject:longitude forKey:@"lng"];
296296

297297
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:json];
298-
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
298+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
299299
}];
300300
}
301301

@@ -319,7 +319,7 @@ -(void)setTitle:(CDVInvokedUrlCommand *)command
319319

320320

321321
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
322-
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
322+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
323323
}];
324324
}];
325325
}
@@ -338,7 +338,7 @@ -(void)setSnippet:(CDVInvokedUrlCommand *)command
338338
marker.snippet = [command.arguments objectAtIndex:1];
339339

340340
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
341-
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
341+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
342342
}];
343343
}];
344344
}
@@ -358,7 +358,7 @@ -(void)remove:(CDVInvokedUrlCommand *)command
358358
marker = nil;
359359

360360
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
361-
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
361+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
362362
}];
363363
}];
364364
}
@@ -424,7 +424,7 @@ -(void)setIconAnchor:(CDVInvokedUrlCommand *)command
424424
}
425425

426426
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
427-
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
427+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
428428
}];
429429
}
430430

@@ -450,7 +450,7 @@ -(void)setInfoWindowAnchor:(CDVInvokedUrlCommand *)command
450450
} else {
451451
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
452452
}
453-
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
453+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
454454
}];
455455

456456
}];
@@ -470,7 +470,7 @@ -(void)setOpacity:(CDVInvokedUrlCommand *)command
470470
marker.opacity = [[command.arguments objectAtIndex:1] floatValue];
471471

472472
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
473-
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
473+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
474474
}];
475475
}];
476476
}
@@ -488,7 +488,7 @@ -(void)setZIndex:(CDVInvokedUrlCommand *)command
488488
marker.zIndex = [[command.arguments objectAtIndex:1] intValue];
489489

490490
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
491-
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
491+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
492492
}];
493493
}];
494494
}
@@ -507,7 +507,7 @@ -(void)setDraggable:(CDVInvokedUrlCommand *)command
507507
[marker setDraggable:isEnabled];
508508

509509
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
510-
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
510+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
511511
}];
512512
}];
513513
}
@@ -530,7 +530,7 @@ -(void)setDisableAutoPan:(CDVInvokedUrlCommand *)command
530530
NSLog(@"--->propertyId = %@", propertyId);
531531

532532
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
533-
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
533+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
534534
}];
535535
}
536536

@@ -560,7 +560,7 @@ -(void)setVisible:(CDVInvokedUrlCommand *)command
560560
[self.mapCtrl.objects setObject:properties forKey:propertyId];
561561

562562
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
563-
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
563+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
564564
}];
565565
}];
566566
}
@@ -582,7 +582,7 @@ -(void)setPosition:(CDVInvokedUrlCommand *)command
582582
[marker setPosition:position];
583583

584584
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
585-
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
585+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
586586
}];
587587
}];
588588
}
@@ -601,7 +601,7 @@ -(void)setFlat:(CDVInvokedUrlCommand *)command
601601
[marker setFlat: isFlat];
602602

603603
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
604-
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
604+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
605605
}];
606606
}];
607607
}
@@ -645,15 +645,15 @@ -(void)setIcon:(CDVInvokedUrlCommand *)command
645645
[iconProperty setObject:[rgbColor parsePluginColor] forKey:@"iconColor"];
646646
}
647647

648-
CDVCommandDelegateImpl *cmdDelegate = (CDVCommandDelegateImpl *)self.commandDelegate;
648+
__weak __auto_type weakSelf = self;
649649
[self setIcon_:marker iconProperty:iconProperty callbackBlock:^(BOOL successed, id resultObj) {
650650
CDVPluginResult* pluginResult;
651651
if (successed == NO) {
652652
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:resultObj];
653653
} else {
654654
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
655655
}
656-
[cmdDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
656+
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
657657
}];
658658
}];
659659
}
@@ -671,7 +671,7 @@ -(void)setRotation:(CDVInvokedUrlCommand *)command
671671
[marker setRotation:degrees];
672672

673673
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
674-
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
674+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
675675
}];
676676
}];
677677
}
@@ -686,11 +686,11 @@ -(void)setAnimation:(CDVInvokedUrlCommand *)command
686686
GMSMarker *marker = [self.mapCtrl.objects objectForKey:markerId];
687687

688688
NSString *animation = [command.arguments objectAtIndex:1];
689-
CDVCommandDelegateImpl *cmdDelegate = (CDVCommandDelegateImpl *)self.commandDelegate;
689+
__weak __auto_type weakSelf = self;
690690

691691
[self setMarkerAnimation_:animation marker:marker callbackBlock:^(void) {
692692
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
693-
[cmdDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
693+
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
694694
}];
695695
}];
696696
}];

src/ios/GoogleMaps/PluginMarkerCluster.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ - (void)redrawClusters:(CDVInvokedUrlCommand*)command {
453453
- (void) endRedraw:(CDVInvokedUrlCommand*)command {
454454
NSLog(@"--->allResults = %@", self.allResults);
455455
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:self.allResults];
456-
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
456+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
457457
}
458458

459459
- (void) deleteProcess:(NSDictionary *) params clusterId:(NSString *)clusterId{

src/ios/GoogleMaps/PluginUtil.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#import "IPluginProtocol.h"
2121
#import "PluginViewController.h"
2222
#import <Cordova/CDVCommandDelegate.h>
23-
#import <Cordova/CDVCommandDelegateImpl.h>
2423

2524
typedef void (^MYCompletionHandler)(NSError *error);
2625

@@ -49,10 +48,6 @@ typedef void (^MYCompletionHandler)(NSError *error);
4948
- (UIImage *)resize:(CGFloat)width height:(CGFloat)height;
5049
@end
5150

52-
@interface CDVCommandDelegateImpl (GoogleMapsPlugin)
53-
- (void)hookSendPluginResult:(CDVPluginResult*)result callbackId:(NSString*)callbackId;
54-
@end
55-
5651
//
5752
// animationDidStop for group animation
5853
// http://stackoverflow.com/a/28051909/697856

0 commit comments

Comments
 (0)