Bug fix: can not load image files if the app uses WKWebView (ionic) in iOS
MODIFY
src/ios/GoogleMaps/PluginGroundOverlay.m
src/ios/GoogleMaps/PluginGroundOverlay.m
NSURL *url;
if ([clsName isEqualToString:@"UIWebView"]) {
url = ((UIWebView *)cdvViewController.webView).request.URL;
- } else {
- url = [webview URL];
- }
NSString *currentURL = url.absoluteString;
currentURL = [currentURL stringByDeletingLastPathComponent];
currentURL = [currentURL stringByReplacingOccurrencesOfString:@"file:" withString:@""];
currentURL = [currentURL stringByReplacingOccurrencesOfString:@"//" withString:@"/"];
currentURL = [currentURL stringByReplacingOccurrencesOfString:@"%20" withString:@" "];
urlStr = [NSString stringWithFormat:@"file://%@/%@", currentURL, urlStr];
+ } else {
+ //------------------------------------------
+ // WKWebView URL is use http:// always
+ //------------------------------------------
+ dispatch_sync(dispatch_get_main_queue(), ^{
+ NSURL *url = [webview URL];
+ NSString *currentURL = url.absoluteString;
+ currentURL = [currentURL stringByDeletingLastPathComponent];
+ url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", currentURL, urlStr]];
+
+ [self downloadImageWithURL:url completionBlock:^(BOOL succeeded, UIImage *image) {
+
+ if (!succeeded) {
+ completionHandler(NO);
+ return;
+ }
+
+ dispatch_async(dispatch_get_main_queue(), ^{
+ groundOverlay.icon = image;
+ completionHandler(YES);
+ });
+
+ }];
+ });
+ return;
+ }
} else {
urlStr = [NSString stringWithFormat:@"file://%@", urlStr];
}

MODIFY
src/ios/GoogleMaps/PluginMarker.m
src/ios/GoogleMaps/PluginMarker.m
NSURL *url;
if ([clsName isEqualToString:@"UIWebView"]) {
url = ((UIWebView *)cdvViewController.webView).request.URL;
- } else {
- url = [webview URL];
- }
NSString *currentURL = url.absoluteString;
// remove page unchor (i.e index.html#page=test, index.html?key=value)
if (self.mapCtrl.debuggable) {
NSLog(@"iconPath = %@", iconPath);
}
+ } else {
+ //------------------------------------------
+ // WKWebView URL is use http:// always
+ //------------------------------------------
+
+ dispatch_sync(dispatch_get_main_queue(), ^{
+ NSURL *url = [webview URL];
+ NSString *currentURL = url.absoluteString;
+ currentURL = [currentURL stringByDeletingLastPathComponent];
+ //url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", currentURL, iconPath]];
+
+ //
+ // Load the icon from over the internet
+ //
+
+ dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
+ dispatch_async(queue, ^{
+
+ NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", currentURL, iconPath]];
+
+ [self downloadImageWithURL:url completionBlock:^(BOOL succeeded, UIImage *image) {
+
+ if (!succeeded) {
+ NSLog(@"[fail] url = %@", url);
+ // The `visible` property
+ if (iconProperty[@"visible"]) {
+ marker.map = self.mapCtrl.map;
+ }
+ if ([[UIImageCache sharedInstance].iconCacheKeys objectForKey:iconCacheKey]) {
+ [[UIImageCache sharedInstance].iconCacheKeys removeObjectForKey:iconCacheKey];
+ }
+
+ callbackBlock(NO, [NSString stringWithFormat:@"Can not load image from '%@'.", url]);
+ return;
+ }
+
+
+ if (self.mapCtrl.debuggable) {
+ NSLog(@"[success] url = %@", url);
+ }
+
+ if (width && height) {
+ image = [image resize:width height:height];
+ }
+
+ // Cache the icon image
+ NSString *iconKey = [NSString stringWithFormat:@"marker_icon_%@", marker.userData];
+ [[UIImageCache sharedInstance] cacheImage:image forKey:iconCacheKey];
+ [self.mapCtrl.objects setObject:iconCacheKey forKey:iconKey];
+ [[UIImageCache sharedInstance].iconCacheKeys setObject:[NSNumber numberWithInt:1] forKey:iconCacheKey];;
+ //NSLog(@"--->confirm: key: %@, iconCacheKey : %@", iconKey, [self.mapCtrl.objects objectForKey:iconKey]);
+
+ // Draw label
+ if ([iconProperty objectForKey:@"label"]) {
+ image = [self drawLabel:image labelOptions:[iconProperty objectForKey:@"label"]];
+ }
+
+ dispatch_async(dispatch_get_main_queue(), ^{
+ marker.icon = image;
+
+ // The `anchor` property for the icon
+ if ([iconProperty valueForKey:@"anchor"]) {
+ NSArray *points = [iconProperty valueForKey:@"anchor"];
+ CGFloat anchorX = [[points objectAtIndex:0] floatValue] / image.size.width;
+ CGFloat anchorY = [[points objectAtIndex:1] floatValue] / image.size.height;
+ marker.groundAnchor = CGPointMake(anchorX, anchorY);
+ }
+
+
+ // The `infoWindowAnchor` property
+ if ([iconProperty valueForKey:@"infoWindowAnchor"]) {
+ NSArray *points = [iconProperty valueForKey:@"infoWindowAnchor"];
+ CGFloat anchorX = [[points objectAtIndex:0] floatValue] / image.size.width;
+ CGFloat anchorY = [[points objectAtIndex:1] floatValue] / image.size.height;
+ marker.infoWindowAnchor = CGPointMake(anchorX, anchorY);
+ }
+
+ // The `visible` property
+ if (iconProperty[@"visible"]) {
+ marker.map = self.mapCtrl.map;
+ }
+
+
+ if (animation) {
+ // Do animation, then send the result
+ [self setMarkerAnimation_:animation marker:marker callbackBlock:^(void) {
+ callbackBlock(YES, marker);
+ }];
+ } else {
+ // Send the result
+ callbackBlock(YES, marker);
+ }
+
+ });
+
+
+ }];
+
+ });
+
+
+
+
+ });
+
+ return;
+ }
}

Bug fix: can not load image files if the app uses WKWebView (ionic) in iOS