Skip to content

Commit c4693cf

Browse files
committed
Merge branch 'pull_807'
2 parents 3031283 + 21373a1 commit c4693cf

12 files changed

Lines changed: 214 additions & 48 deletions

plugin.xml

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55
<clobbers target="plugin.google.maps" />
66
</js-module>
77

8-
8+
99
<description>Google Maps native SDK for Android and iOS</description>
1010
<repo>https://github.com/mapsplugin/cordova-plugin-googlemaps</repo>
1111
<issue>https://github.com/mapsplugin/cordova-plugin-googlemaps/issues</issue>
1212

1313
<license>Apache 2.0</license>
14-
14+
1515
<keywords>google,maps,geo</keywords>
16-
16+
1717
<engines>
1818
<engine name="cordova" version=">=3.5.0" />
1919
</engines>
20-
20+
2121
<!-- android -->
2222
<platform name="android">
2323
<preference name="API_KEY_FOR_ANDROID" />
24-
24+
2525
<info>
2626
In order to run this plugin, you need to obtain Google Maps API key for Android.
2727
Visit https://github.com/mapsplugin/cordova-plugin-googlemaps/wiki/Installation
@@ -67,7 +67,7 @@
6767
<source-file src="src/android/plugin/google/maps/PluginTileProvider.java" target-dir="src/plugin/google/maps" />
6868
<source-file src="src/android/plugin/google/maps/PluginUtil.java" target-dir="src/plugin/google/maps" />
6969
<source-file src="src/android/plugin/google/maps/PluginAsyncInterface.java" target-dir="src/plugin/google/maps" />
70-
70+
7171
<config-file target="AndroidManifest.xml" parent="/manifest/application">
7272
<meta-data
7373
android:name="com.google.android.maps.v2.API_KEY"
@@ -76,7 +76,7 @@
7676
<meta-data android:name="com.google.android.gms.version"
7777
android:value="@integer/google_play_services_version" />
7878
</config-file>
79-
79+
8080
<config-file target="AndroidManifest.xml" parent="/manifest">
8181
<uses-permission android:name="android.permission.INTERNET"/>
8282
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
@@ -89,11 +89,11 @@
8989
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
9090
</config-file>
9191
</platform>
92-
92+
9393
<!-- ios -->
9494
<platform name="ios">
9595
<preference name="API_KEY_FOR_IOS" />
96-
96+
9797
<info>
9898
In order to run this plugin, you need to obtain Google Maps API key for iOS.
9999
Visit https://github.com/mapsplugin/cordova-plugin-googlemaps/wiki/Installation
@@ -112,6 +112,33 @@
112112
<feature name="Geocoder">
113113
<param name="ios-package" value="Geocoder" />
114114
</feature>
115+
<feature name="Map">
116+
<param name="ios-package" value="Map" />
117+
</feature>
118+
<feature name="Circle">
119+
<param name="ios-package" value="Circle" />
120+
</feature>
121+
<feature name="Geocoder">
122+
<param name="ios-package" value="Geocoder" />
123+
</feature>
124+
<feature name="GroundOverlay">
125+
<param name="ios-package" value="GroundOvderlay" />
126+
</feature>
127+
<feature name="KmlOverlay">
128+
<param name="ios-package" value="KmlOverlay" />
129+
</feature>
130+
<feature name="Marker">
131+
<param name="ios-package" value="Marker" />
132+
</feature>
133+
<feature name="Polygon">
134+
<param name="ios-package" value="Polygon" />
135+
</feature>
136+
<feature name="Polyline">
137+
<param name="ios-package" value="Polyline" />
138+
</feature>
139+
<feature name="TileOverlay">
140+
<param name="ios-package" value="TileOverlay" />
141+
</feature>
115142
</config-file>
116143

117144
<header-file src="src/ios/GoogleMaps/Circle.h" />
@@ -164,7 +191,7 @@
164191
<config-file target="*-Info.plist" parent="NSLocationAlwaysUsageDescription">
165192
<string>Trace your location on the map</string>
166193
</config-file>
167-
194+
168195
<config-file target="*-Info.plist" parent="CFBundleURLTypes">
169196
<array>
170197
<dict>
@@ -179,7 +206,7 @@
179206
</dict>
180207
</array>
181208
</config-file>
182-
209+
183210
<dependency id="com.googlemaps.ios" url="https://bitbucket.org/nightstomp/cordova-plugin-googlemaps-sdk.git" commit="master" />
184211
</platform>
185212
</plugin>

src/ios/GoogleMaps/GoogleMaps.m

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ @implementation GoogleMaps
1212

1313
- (void)pluginInitialize
1414
{
15+
#if CORDOVA_VERSION_MIN_REQUIRED >= __CORDOVA_4_0_0
16+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pageDidLoad) name:CDVPageDidLoadNotification object:nil];
17+
#endif
1518
self.licenseLayer = nil;
1619
self.mapCtrl.isFullScreen = YES;
1720
self.locationCommandQueue = [[NSMutableArray alloc] init];
@@ -46,8 +49,7 @@ - (void)pluginInitialize
4649
}
4750

4851
[self.viewController.view addSubview:self.pluginLayer];
49-
50-
52+
5153

5254
NSString *APIKey = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"Google Maps API Key"];
5355
if (APIKey == nil) {
@@ -134,6 +136,11 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
134136
[self.pluginScrollView.debugView setNeedsDisplay];
135137
}
136138

139+
-(void)pageDidLoad {
140+
self.webView.backgroundColor = [UIColor clearColor];
141+
self.webView.opaque = NO;
142+
}
143+
137144
/**
138145
* Intialize the map
139146
*/
@@ -173,7 +180,11 @@ - (void)getMap:(CDVInvokedUrlCommand *)command {
173180

174181

175182
// Create an instance of Map Class
183+
#if CORDOVA_VERSION_MIN_REQUIRED >= __CORDOVA_4_0_0
184+
Map *mapClass = [(CDVViewController*)self.viewController getCommandInstance:@"Map"];
185+
#else
176186
Map *mapClass = [[NSClassFromString(@"Map")alloc] initWithWebView:self.webView];
187+
#endif
177188
mapClass.commandDelegate = self.commandDelegate;
178189
[mapClass setGoogleMapsViewController:self.mapCtrl];
179190
[self.mapCtrl.plugins setObject:mapClass forKey:@"Map"];
@@ -242,7 +253,11 @@ - (void)exec:(CDVInvokedUrlCommand *)command {
242253

243254
pluginClass = [self.mapCtrl.plugins objectForKey:className];
244255
if (!pluginClass) {
245-
pluginClass = [[NSClassFromString(className)alloc] initWithWebView:self.webView];
256+
#if CORDOVA_VERSION_MIN_REQUIRED >= __CORDOVA_4_0_0
257+
pluginClass = [(CDVViewController*)self.viewController getCommandInstance:className];
258+
#else
259+
pluginClass = [[NSClassFromString(className)alloc] initWithWebView:self.webView];
260+
#endif
246261
if (pluginClass) {
247262
pluginClass.commandDelegate = self.commandDelegate;
248263
[pluginClass setGoogleMapsViewController:self.mapCtrl];
@@ -318,7 +333,11 @@ - (void)_removeMapView{
318333
*/
319334
//Notify to the JS
320335
NSString* jsString = [NSString stringWithFormat:@"plugin.google.maps.Map._onMapEvent('map_close');"];
321-
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
336+
if ([self.webView respondsToSelector:@selector(stringByEvaluatingJavaScriptFromString:)]) {
337+
[self.webView performSelector:@selector(stringByEvaluatingJavaScriptFromString:) withObject:jsString];
338+
} else if ([self.webView respondsToSelector:@selector(evaluateJavaScript:completionHandler:)]) {
339+
[self.webView performSelector:@selector(evaluateJavaScript:completionHandler:) withObject:jsString withObject:nil];
340+
}
322341
}
323342

324343
/**

src/ios/GoogleMaps/GoogleMapsViewController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
@interface GoogleMapsViewController : UIViewController<GMSMapViewDelegate, GMSIndoorDisplayDelegate>
1616

1717
@property (nonatomic, strong) GMSMapView* map;
18-
@property (nonatomic, strong) UIWebView* webView;
18+
@property (nonatomic, strong) UIView* webView;
1919
@property (nonatomic, strong) NSMutableDictionary* overlayManager;
2020
@property (nonatomic, readwrite, strong) NSMutableDictionary* plugins;
2121
@property (nonatomic) BOOL isFullScreen;

src/ios/GoogleMaps/GoogleMapsViewController.m

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
//
88

99
#import "GoogleMapsViewController.h"
10+
#if CORDOVA_VERSION_MIN_REQUIRED < __CORDOVA_4_0_0
1011
#import <Cordova/CDVJSON.h>
12+
#endif
1113

1214

1315
@implementation GoogleMapsViewController
@@ -176,8 +178,13 @@ - (void)didReceiveMemoryWarning
176178
* camera to move such that it is centered on the user location.
177179
*/
178180
- (BOOL)didTapMyLocationButtonForMapView:(GMSMapView *)mapView {
179-
[self.webView stringByEvaluatingJavaScriptFromString:@"plugin.google.maps.Map._onMapEvent('my_location_button_click');"];
180-
return NO;
181+
NSString *jsString = @"plugin.google.maps.Map._onMapEvent('my_location_button_click');";
182+
if ([self.webView respondsToSelector:@selector(stringByEvaluatingJavaScriptFromString:)]) {
183+
[self.webView performSelector:@selector(stringByEvaluatingJavaScriptFromString:) withObject:jsString];
184+
} else if ([self.webView respondsToSelector:@selector(evaluateJavaScript:completionHandler:)]) {
185+
[self.webView performSelector:@selector(evaluateJavaScript:completionHandler:) withObject:jsString withObject:nil];
186+
}
187+
return NO;
181188
}
182189

183190
#pragma mark - GMSMapViewDelegate
@@ -204,7 +211,11 @@ - (void) mapView:(GMSMapView *)mapView willMove:(BOOL)gesture
204211
dispatch_sync(gueue, ^{
205212

206213
NSString* jsString = [NSString stringWithFormat:@"plugin.google.maps.Map._onMapEvent('will_move', %@);", gesture ? @"true": @"false"];
207-
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
214+
if ([self.webView respondsToSelector:@selector(stringByEvaluatingJavaScriptFromString:)]) {
215+
[self.webView performSelector:@selector(stringByEvaluatingJavaScriptFromString:) withObject:jsString];
216+
} else if ([self.webView respondsToSelector:@selector(evaluateJavaScript:completionHandler:)]) {
217+
[self.webView performSelector:@selector(evaluateJavaScript:completionHandler:) withObject:jsString withObject:nil];
218+
}
208219
});
209220
}
210221

@@ -291,7 +302,11 @@ - (void)triggerMapEvent: (NSString *)eventName coordinate:(CLLocationCoordinate2
291302
{
292303
NSString* jsString = [NSString stringWithFormat:@"plugin.google.maps.Map._onMapEvent('%@', new window.plugin.google.maps.LatLng(%f,%f));",
293304
eventName, coordinate.latitude, coordinate.longitude];
294-
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
305+
if ([self.webView respondsToSelector:@selector(stringByEvaluatingJavaScriptFromString:)]) {
306+
[self.webView performSelector:@selector(stringByEvaluatingJavaScriptFromString:) withObject:jsString];
307+
} else if ([self.webView respondsToSelector:@selector(evaluateJavaScript:completionHandler:)]) {
308+
[self.webView performSelector:@selector(evaluateJavaScript:completionHandler:) withObject:jsString withObject:nil];
309+
}
295310
}
296311
/**
297312
* Involve App._onCameraEvent
@@ -315,7 +330,11 @@ - (void)triggerCameraEvent: (NSString *)eventName position:(GMSCameraPosition *)
315330
NSString* sourceArrayString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
316331
NSString* jsString = [NSString stringWithFormat:@"plugin.google.maps.Map._onCameraEvent('%@', %@);", eventName, sourceArrayString];
317332

318-
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
333+
if ([self.webView respondsToSelector:@selector(stringByEvaluatingJavaScriptFromString:)]) {
334+
[self.webView performSelector:@selector(stringByEvaluatingJavaScriptFromString:) withObject:jsString];
335+
} else if ([self.webView respondsToSelector:@selector(evaluateJavaScript:completionHandler:)]) {
336+
[self.webView performSelector:@selector(evaluateJavaScript:completionHandler:) withObject:jsString withObject:nil];
337+
}
319338
}
320339

321340

@@ -326,7 +345,11 @@ - (void)triggerMarkerEvent: (NSString *)eventName marker:(GMSMarker *)marker
326345
{
327346
NSString* jsString = [NSString stringWithFormat:@"plugin.google.maps.Map._onMarkerEvent('%@', 'marker_%lu');",
328347
eventName, (unsigned long)marker.hash];
329-
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
348+
if ([self.webView respondsToSelector:@selector(stringByEvaluatingJavaScriptFromString:)]) {
349+
[self.webView performSelector:@selector(stringByEvaluatingJavaScriptFromString:) withObject:jsString];
350+
} else if ([self.webView respondsToSelector:@selector(evaluateJavaScript:completionHandler:)]) {
351+
[self.webView performSelector:@selector(evaluateJavaScript:completionHandler:) withObject:jsString withObject:nil];
352+
}
330353
}
331354

332355
/**
@@ -336,7 +359,11 @@ - (void)triggerOverlayEvent: (NSString *)eventName id:(NSString *) id
336359
{
337360
NSString* jsString = [NSString stringWithFormat:@"plugin.google.maps.Map._onOverlayEvent('%@', '%@');",
338361
eventName, id];
339-
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
362+
if ([self.webView respondsToSelector:@selector(stringByEvaluatingJavaScriptFromString:)]) {
363+
[self.webView performSelector:@selector(stringByEvaluatingJavaScriptFromString:) withObject:jsString];
364+
} else if ([self.webView respondsToSelector:@selector(evaluateJavaScript:completionHandler:)]) {
365+
[self.webView performSelector:@selector(evaluateJavaScript:completionHandler:) withObject:jsString withObject:nil];
366+
}
340367
}
341368

342369
//future support: custom info window
@@ -714,7 +741,11 @@ -(UIImage *)loadImageFromGoogleMap:(NSString *)fileName {
714741
- (void) didChangeActiveBuilding: (GMSIndoorBuilding *)building {
715742
//Notify to the JS
716743
NSString* jsString = @"javascript:plugin.google.maps.Map._onMapEvent('indoor_building_focused')";
717-
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
744+
if ([self.webView respondsToSelector:@selector(stringByEvaluatingJavaScriptFromString:)]) {
745+
[self.webView performSelector:@selector(stringByEvaluatingJavaScriptFromString:) withObject:jsString];
746+
} else if ([self.webView respondsToSelector:@selector(evaluateJavaScript:completionHandler:)]) {
747+
[self.webView performSelector:@selector(evaluateJavaScript:completionHandler:) withObject:jsString withObject:nil];
748+
}
718749
}
719750

720751
- (void) didChangeActiveLevel: (GMSIndoorLevel *)activeLevel {
@@ -746,7 +777,11 @@ - (void) didChangeActiveLevel: (GMSIndoorLevel *)activeLevel {
746777
encoding:NSUTF8StringEncoding];
747778
NSString *jsString = [NSString stringWithFormat:@"javascript:plugin.google.maps.Map._onMapEvent('indoor_level_activated', %@)", JSONstring];
748779

749-
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
780+
if ([self.webView respondsToSelector:@selector(stringByEvaluatingJavaScriptFromString:)]) {
781+
[self.webView performSelector:@selector(stringByEvaluatingJavaScriptFromString:) withObject:jsString];
782+
} else if ([self.webView respondsToSelector:@selector(evaluateJavaScript:completionHandler:)]) {
783+
[self.webView performSelector:@selector(evaluateJavaScript:completionHandler:) withObject:jsString withObject:nil];
784+
}
750785
}
751786

752787

src/ios/GoogleMaps/GroundOverlay.m

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,26 @@ - (void)_setImage:(GMSGroundOverlay *)layer urlStr:(NSString *)urlStr completion
9797

9898
range = [urlStr rangeOfString:@"./"];
9999
if (range.location != NSNotFound) {
100-
NSString *currentPath = [self.webView.request.URL absoluteString];
100+
SEL requestSelector = NSSelectorFromString(@"request");
101+
SEL urlSelector = NSSelectorFromString(@"URL");
102+
NSString *currentPath = @"";
103+
if ([self.webView respondsToSelector:requestSelector]) {
104+
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[self.webView class] instanceMethodSignatureForSelector:requestSelector]];
105+
[invocation setSelector:requestSelector];
106+
[invocation setTarget:self.webView];
107+
[invocation invoke];
108+
NSURLRequest *request;
109+
[invocation getReturnValue:&request];
110+
currentPath = [request.URL absoluteString];
111+
} else if ([self.webView respondsToSelector:urlSelector]) {
112+
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[self.webView class] instanceMethodSignatureForSelector:urlSelector]];
113+
[invocation setSelector:urlSelector];
114+
[invocation setTarget:self.webView];
115+
[invocation invoke];
116+
NSURL *URL;
117+
[invocation getReturnValue:&URL];
118+
currentPath = [URL absoluteString];
119+
}
101120
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[^\\/]*$" options:NSRegularExpressionCaseInsensitive error:&error];
102121
currentPath= [regex stringByReplacingMatchesInString:currentPath options:0 range:NSMakeRange(0, [currentPath length]) withTemplate:@""];
103122
urlStr = [urlStr stringByReplacingOccurrencesOfString:@"./" withString:currentPath];

src/ios/GoogleMaps/KmlOverlay.m

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,26 @@ -(void)createKmlOverlay:(CDVInvokedUrlCommand *)command
3737

3838
range = [urlStr rangeOfString:@"./"];
3939
if (range.location != NSNotFound) {
40-
NSString *currentPath = [self.webView.request.URL absoluteString];
40+
SEL requestSelector = NSSelectorFromString(@"request");
41+
SEL urlSelector = NSSelectorFromString(@"URL");
42+
NSString *currentPath = @"";
43+
if ([self.webView respondsToSelector:requestSelector]) {
44+
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[self.webView class] instanceMethodSignatureForSelector:requestSelector]];
45+
[invocation setSelector:requestSelector];
46+
[invocation setTarget:self.webView];
47+
[invocation invoke];
48+
NSURLRequest *request;
49+
[invocation getReturnValue:&request];
50+
currentPath = [request.URL absoluteString];
51+
} else if ([self.webView respondsToSelector:urlSelector]) {
52+
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[self.webView class] instanceMethodSignatureForSelector:urlSelector]];
53+
[invocation setSelector:urlSelector];
54+
[invocation setTarget:self.webView];
55+
[invocation invoke];
56+
NSURL *URL;
57+
[invocation getReturnValue:&URL];
58+
currentPath = [URL absoluteString];
59+
}
4160
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[^\\/]*$" options:NSRegularExpressionCaseInsensitive error:&error];
4261
currentPath= [regex stringByReplacingMatchesInString:currentPath options:0 range:NSMakeRange(0, [currentPath length]) withTemplate:@""];
4362
urlStr = [urlStr stringByReplacingOccurrencesOfString:@"./" withString:currentPath];
@@ -582,7 +601,11 @@ -(void)_execOtherClassMethod:(NSString *)className methodName:(NSString *)method
582601

583602
CDVPlugin<MyPlgunProtocol> *pluginClass = [self.mapCtrl.plugins objectForKey:className];
584603
if (!pluginClass) {
604+
#if CORDOVA_VERSION_MIN_REQUIRED >= __CORDOVA_4_0_0
605+
pluginClass = [(CDVViewController*)self.viewController getCommandInstance:className];
606+
#else
585607
pluginClass = [[NSClassFromString(className)alloc] initWithWebView:self.webView];
608+
#endif
586609
if (pluginClass) {
587610
pluginClass.commandDelegate = self.commandDelegate;
588611
[pluginClass setGoogleMapsViewController:self.mapCtrl];
@@ -598,7 +621,11 @@ -(void)_execOtherClassMethod:(NSString *)className methodName:(NSString *)method
598621

599622
-(void)evalJsHelper:(NSString*)jsString
600623
{
601-
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
624+
if ([self.webView respondsToSelector:@selector(stringByEvaluatingJavaScriptFromString:)]) {
625+
[self.webView performSelector:@selector(stringByEvaluatingJavaScriptFromString:) withObject:jsString];
626+
} else if ([self.webView respondsToSelector:@selector(evaluateJavaScript:completionHandler:)]) {
627+
[self.webView performSelector:@selector(evaluateJavaScript:completionHandler:) withObject:jsString withObject:nil];
628+
}
602629
}
603630

604631
-(void)_implementToMap:(NSString *)className options:(NSDictionary *)options needJSCallback:(BOOL)needJSCallback

0 commit comments

Comments
 (0)