Fix: can not load image file for marker if app runs on WKWebView but url is local path
MODIFY
plugin.xml
plugin.xml
<?xml version='1.0' encoding='utf-8'?>
-<plugin id="cordova-plugin-googlemaps" version="2.3.8" 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.3.9-beta-20180718-1052" 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 />

MODIFY
src/ios/GoogleMaps/PluginGroundOverlay.m
src/ios/GoogleMaps/PluginGroundOverlay.m
{
[self.mapCtrl.executeQueue addOperationWithBlock:^{
+ NSString *iconPath = url.absoluteString;
+
+ if ([iconPath hasPrefix:@"file://"]) {
+ iconPath = [iconPath stringByReplacingOccurrencesOfString:@"file://" withString:@""];
+ if (![iconPath hasPrefix:@"/"]) {
+ iconPath = [NSString stringWithFormat:@"/%@", iconPath];
+ }
+ NSFileManager *fileManager = [NSFileManager defaultManager];
+ if (![fileManager fileExistsAtPath:iconPath]) {
+ //if (self.mapCtrl.debuggable) {
+ NSLog(@"(error)There is no file at '%@'.", iconPath);
+ //}
+ //[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
+ completionBlock(NO, nil);
+ return;
+ }
+
+ UIImage *image = [UIImage imageNamed:iconPath];
+ if (image) {
+ completionBlock(YES, image);
+ return;
+ }
+ }
+
+
+
NSURLRequest *req = [NSURLRequest requestWithURL:url
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:5];
}];
[getTask resume];
- //-------------------------------------------------------------
- // NSURLConnection sendAsynchronousRequest is deprecated.
- //-------------------------------------------------------------
- /*
- [NSURLConnection sendAsynchronousRequest:req
- queue:self.mapCtrl.executeQueue
- completionHandler:^(NSURLResponse *res, NSData *data, NSError *error) {
- if ( !error ) {
- [self.icons setObject:data forKey:uniqueKey cost:data.length];
- UIImage *image = [UIImage imageWithData:data];
- completionBlock(YES, image);
- } else {
- completionBlock(NO, nil);
- }
-
- }];
- */
}];

MODIFY
src/ios/GoogleMaps/PluginMarker.m
src/ios/GoogleMaps/PluginMarker.m
{
[self.mapCtrl.executeQueue addOperationWithBlock:^{
NSString *markerId = [command.arguments objectAtIndex:0];
- GMSMarker *marker = [self.mapCtrl.objects objectForKey:markerId];
BOOL disableAutoPan = [[command.arguments objectAtIndex:1] boolValue];
NSString *propertyId = [NSString stringWithFormat:@"marker_property_%@",markerId];
}
} else {
//------------------------------------------
- // WKWebView URL is use http:// always
+ // WKWebView
//------------------------------------------
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
//
// Load the icon from over the internet
//
- [self.mapCtrl.executeQueue addOperationWithBlock:^{
-
[self downloadImageWithURL:url completionBlock:^(BOOL succeeded, UIImage *image) {
if (!succeeded) {
}];
- }];
-
// 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:iconPath];
[self downloadImageWithURL:url completionBlock:^(BOOL succeeded, UIImage *image) {
}];
- });
-
}
- (UIImage *)drawLabel:(UIImage *) image labelOptions:(NSDictionary *)labelOptions {
{
[self.mapCtrl.executeQueue addOperationWithBlock:^{
+ NSString *iconPath = url.absoluteString;
+ NSString *uniqueKey = url.absoluteString;
+
+ if ([iconPath hasPrefix:@"file://"]) {
+ iconPath = [iconPath stringByReplacingOccurrencesOfString:@"file://" withString:@""];
+ if (![iconPath hasPrefix:@"/"]) {
+ iconPath = [NSString stringWithFormat:@"/%@", iconPath];
+ }
+ NSFileManager *fileManager = [NSFileManager defaultManager];
+ if (![fileManager fileExistsAtPath:iconPath]) {
+ //if (self.mapCtrl.debuggable) {
+ NSLog(@"(error)There is no file at '%@'.", iconPath);
+ //}
+ //[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
+ completionBlock(NO, nil);
+ return;
+ }
+
+ UIImage *image = [UIImage imageNamed:iconPath];
+ if (image) {
+ [[UIImageCache sharedInstance] cacheImage:image forKey:uniqueKey];
+ completionBlock(YES, image);
+ return;
+ }
+ }
+
+
+
NSURLRequest *req = [NSURLRequest requestWithURL:url
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:5];
return;
}
- NSString *uniqueKey = url.absoluteString;
UIImage *image = [[UIImageCache sharedInstance] getCachedImageForKey:uniqueKey];
if (image != nil) {
completionBlock(YES, image);

Fix: can not load image file for marker if app runs on WKWebView but url is local path #2344