【发布时间】:2016-06-26 07:41:35
【问题描述】:
我想在我的 Google 地图的信息窗口中显示 Tide Times。
我已经尝试过使用天气小部件,效果很好:http://jsfiddle.net/nvwjnrhy/
但是,尝试使用 Tide Times 进行类似操作是行不通的:http://jsfiddle.net/nvwjnrhy/1/
这是我当前的完整代码:
var geocoder = new google.maps.Geocoder();
var marker;
var infoWindow;
var map;
function initialize() {
var mapOptions = {
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
setLocation();
}
function setLocation() {
var address = '2349 Marlton Pike W, Cherry Hill, NJ 08002';
geocoder.geocode({
'address': address
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var position = results[0].geometry.location;
marker = new google.maps.Marker({
map: map,
position: position,
title: 'Venue Name'
});
map.setCenter(marker.getPosition());
var content = document.createElement('div');
var script = document.createElement('script');
script.src = "https://www.tidetimes.org.uk/grimsby-tide-times.js";
content.appendChild(script);
infoWindow = new google.maps.InfoWindow({
content: content
});
google.maps.event.addListener(marker, 'click', function() {
infoWindow.open(map, marker);
});
//infoWindow.open(map, marker); doesn't work
google.maps.event.trigger(marker, 'click'); //still doesn't work
} else {
//
}
});
}
initialize();
//google.maps.event.addDomListener(window, 'load', initialize);
html, body {
width: 100%;
height: 100%;
}
#map-canvas {
width: 100%;
height: 100%;
margin: 10px 0;
color: #000;
}
<script src="http://maps.google.com/maps/api/js?sensor=false&.js"></script>
<div id="map-canvas"></div>
感谢您对此的任何帮助:)
【问题讨论】:
-
显示该 API 信息的代码在哪里?
-
对不起,我不明白这个问题。您可以在此处找到显示潮汐时间所需的一行代码:tidetimes.org.uk/widgets。这有帮助吗? :)
-
我听说
postscribe可能是解决这个问题的有用工具,但我不完全确定在这种情况下如何使用它github.com/krux/postscribe -
我在日志中看到了这个
Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.
标签: javascript jquery google-maps google-maps-api-3 google-maps-markers