gpt4 book ai didi

javascript - Google Maps API 显示空白 map

转载 作者:可可西里 更新时间:2023-11-01 02:19:57 25 4
gpt4 key购买 nike

我确定这是一个基本问题,但我现在已经用头撞墙太多次了,所以希望有人能可怜我!

我有以下示例,但它只是显示一个灰色框,根本没有 map 。谁能告诉我为什么?

我已经检查过我实际上返回了一个结果,它似乎工作正常。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">

<style>
html, body, #map-canvas {margin: 0;padding: 0;height: 100%;}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
var geocoder;
var map;

function initialize()
{
geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': "England"}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(results[0].geometry.location),
mapTypeId: google.maps.MapTypeId.ROADMAP
}

// Let's draw the map
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);

}
else
{
alert("Geocode was not successful for the following reason: " + status);
}
});
}

initialize();
</script>
</head>

<body onload="">
<div id="map-canvas" style="width: 320px; height: 480px;"></div>
</body>
</html>

最佳答案

尝试调整浏览器窗口的大小,摇动浏览器/使用光标将其从浏览器选项卡中拖动,您将看到 map 出现。

由于某些奇怪的原因,在 MVC 局部 View 中,谷歌地图显示为空白,您的 map 正在运行,只是需要调整大小。

用光标摇动浏览器窗口听起来很有趣,但确实有效,我不确定如何最好地描述它。

谢谢,阿努拉格

============================================= ========================

我的最终工作代码如下:

`

<script type="text/javascript">

$(document).ready(function () {
(function () {
var options = {
zoom: 6,
center: new google.maps.LatLng(-2.633333, 37.233334),
mapTypeId: google.maps.MapTypeId.TERRAIN,
mapTypeControl: false
};

// init map
var map = new google.maps.Map(document.getElementById('map_canvas'), options);


var arrLocation = [];
$("#markerDiv").find("div").each(function () {
var Lat = $(this).find("input[id='Latitude']").val();
var Lon = $(this).find("input[id='Longitude']").val();
var Id = $(this).find("input[id='Id']").val();
var AssessmentDet = $(this).find("input[id='AssessmentDateTime']").val();
var LocAcc = $(this).find("input[id='LocationAccuracy']").val();
var assessorName = $(this).find("input[id='AssessorName']").val();
var partnerName = $(this).find("input[id='PartnerName']").val();
arrLocation.push({
Id: Id,
Latitude: Lat,
Longitude: Lon,
AssessmentDate: AssessmentDet,
LocationAccuracy: LocAcc,
AssessorDetail: assessorName,
PartnerName: partnerName
});
});

var allMarkers = [];

for (var i = 0; i < arrLocation.length; i++) {

//final position for marker, could be updated if another marker already exists in same position
var latlng = new google.maps.LatLng(arrLocation[i].Latitude, arrLocation[i].Longitude);
var finalLatLng = latlng;
var comparelatlng = "(" + arrLocation[i].Latitude + "," + arrLocation[i].Longitude + ")";
var copyMarker = arrLocation[i];

var marker = new google.maps.Marker({
position: new google.maps.LatLng(arrLocation[i].Latitude, arrLocation[i].Longitude),
map: map,
title: 'Equine # ' + arrLocation[i].Id,
icon:"abc.png"
});


var markerInfo = "Reference # : <b>" + arrLocation[i].Id + "</b><br/>";
markerInfo = markerInfo + "Assessor : <b>" + arrLocation[i].AssessorDetail + "</b><br/>";
markerInfo = markerInfo + "Date : <b>" + arrLocation[i].AssessmentDate + "</b><br/>";
markerInfo = markerInfo + "Partner : <b>" + arrLocation[i].PartnerName + "</b>";(function (marker, i) {

bindInfoWindow(marker, map, new google.maps.InfoWindow(), markerInfo);
})(marker, i);
}
})();
});

function bindInfoWindow(marker, map, infowindow, html) {
google.maps.event.addListener(marker, 'click', function () {
infowindow.setContent(html);
infowindow.open(map, marker);
});
}


</script>

`

关于javascript - Google Maps API 显示空白 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18509973/

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