gpt4 book ai didi

javascript - 无法在本地 html 文件中的 webview 中加载谷歌地图

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:31:35 26 4
gpt4 key购买 nike

我正在使用一个名为 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 中显示一个空白页面。

最佳答案

试试这段代码

<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">
function init() {
var latlong = new google.maps.LatLng(23.0225, 72.5714);
var myOptions = {
zoom: 15,
center: latlong,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
</script>
</head>
<body onload="init()">
<div id="map_canvas" style="width:100%; height:100%">
</body>
</html>

并使用这个方法

- (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL

关于javascript - 无法在本地 html 文件中的 webview 中加载谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42716654/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com