【发布时间】:2017-07-31 16:42:23
【问题描述】:
我正在使用一个名为 basicmap.html 的本地 html 文件,其中包含
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="map"></div>
<script>
function initMap() {
// Create a map object and specify the DOM element for display.
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
scrollwheel: false,
zoom: 8
});
console.log(map);
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCvjeJZDdkpxCLasVMvTX2raxKkVGUULP8&callback=initMap"
async defer></script>
</body>
</html>
在 viewcontroller.m 中将本地 basicmap.html 文件加载到 webview 中,其中包含以下代码
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIWebView *webView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [[NSBundle mainBundle] URLForResource:@"basicmap" withExtension:@"html"];
[_webView loadRequest:[NSURLRequest requestWithURL:url]];
[self.view addSubview:_webView];
}
@end
输出在 webview 中显示一个空白页面。
【问题讨论】:
-
我还在 info.plist 文件中添加了
NSAppTransportSecurity NSAllowsArbitraryLoads -
使用这个方法 - (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL
-
@Jigar 我使用这个 NSString htmlFile = [[NSBundle mainBundle] pathForResource:@"basic" ofType:@"html" inDirectory:nil]; NSString htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil]; [_webView loadHTMLString:htmlString baseURL: [[NSBundle mainBundle] bundleURL]];但这也行不通/
-
您检查您的 html 文件是否正常工作?
-
@Jigar Html 页面在 Safari/Chrome 中也显示为空白
标签: javascript html ios objective-c google-maps-api-3