gpt4 book ai didi

javascript - 我的 map v3 只是拒绝加载

转载 作者:行者123 更新时间:2023-11-28 08:17:05 24 4
gpt4 key购买 nike

friend 们好,我不知道我的 map v3 有什么问题,它拒绝加载。我在 android 中使用 webview 加载它但没有显示 map 。它只显示按钮和文本字段。这是下面的代码。

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Street View service</title>
<style>
html, body {
height: 100%;
margin: 0px;
padding: 0px
}
#mode{
height:5%;
width:60%
margin-left:0%;
margin-right:0%;
margin-top:5%;
margin-bottom:0%
}
#autocomplete {
font-size:11pt;
align:center;
width: 60%;
margin-left:35%;
margin-right:5%;
margin-top:1%;
margin-bottom:0%
}
#autocomplete1 {
font-size:11pt;
align:center;
width: 60%;
margin-left:35%;
margin-right:5%;
margin-top:1%;
margin-bottom:0%
}
#from {
margin-top:1%;
margin-left:0%;
margin-right:0%;
margin-bottom:0%
}
#to {
margin-top:1%;
margin-left:0%;
margin-right:0%;
margin-bottom:0%
}
#locationField {
margin-left:0%;
margin-right:0%;
margin-top:1%;
margin-bottom:0%
}
#locationField1 {
margin-left:0%;
margin-right:0%;
margin-top:1%;
margin-bottom:0%
}
#button {
align:center;
margin-top:1%;
margin-right:5%;
margin-bottom:0%;
margin-left:35%;
width:60%;
height:8%
}
#map-canvas {
margin-top:1%;
margin-right:0%;
margin-bottom:0%;
margin-left:0%;
width: 100%;
height: 30%
}
</style>

<link type="text/css" rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&libraries=places"></script>
<script>

var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;


function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var chicago = new google.maps.LatLng(41.850033, -87.6500523);
var mapOptions = {
zoom:14,
center: chicago,
mapTypeId: google.maps.MapTypeId.ROADMAP,
streetViewControl: false
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
directionsDisplay.setMap(map);

}


function searchDirection() {
var start = document.getElementById("autocomplete").value;
var end = document.getElementById("autocomplete1").value;
var selectedMode = document.getElementById("mode").value;

var request = {
origin:start,
destination:end,
travelMode: google.maps.TravelMode.[selectedMode]

};
directionsService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(result);
}
});
}

</script>
</head>
<body onload="initialize();">
<div id="text" style="width: 100%; height: 50%;">
<div>
<strong>Direction By : </strong>
<select id="mode" onchange="calcRoute();">
<option value="DRIVING">Driving</option>
<option value="WALKING">Walking</option>
<option value="BICYCLING">Bicycling</option>
<option value="TRANSIT">Transit</option>
</select>
</div>

<div id="locationField">
<strong id="from">From : </strong>
<input id="autocomplete" placeholder="Enter Starting Point"
onFocus="geolocate()" type="text"></input>
</div>

<div id="locationField1">
<strong id="to">To : </strong>
<input id="autocomplete1" placeholder="Enter Destination Point"
onFocus="geolocate()" type="text"></input>
</div>

<input id="button" type="button" name="test" value="Search" style=" font-size:12pt; background-color:#00FF00; color:#A9F5F2;" onclick="searchDirection()">

</div>

<div id="map-canvas"></div>

</body>
</html>

最佳答案

可能是版本问题,请确保您运行的是 Android 4.4.4 Kitkat 以上版本,因为谷歌在这个特定版本中更新了很多与 webView 有关的功能。

除此之外:

由于 webSetting,请确保按照本文档中的步骤进行操作.

您还必须实现 [WebChoromeClient][2]。

并且不要忘记添加所需的权限。

有关代码实现,请单击此[链接][3]。

[2]: https://developer.android.com/reference/android/webkit/WebChromeClient.html#onGeolocationPermissionsShowPrompt(java.lang.String, android.webkit.GeolocationPermissions.Callback)[3]:https://android-er.blogspot.com/2013/06/embed-html-using-google-maps-javascript.html

关于javascript - 我的 map v3 只是拒绝加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28931691/

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