大家好:需要一点帮助...
我正在尝试使用Google Maps API,并且我遵循了官方google网站上的所有说明。 但是,我注意到它并不总是有效。
很多时候,我收到一个错误:
无法加载资源:net :: ERR_CONNECTION_REFUSED https://maps.gstatic.com/intl/en_us/mapfiles/api-3/16/8/main.js 未捕获的TypeError:undefined不是函数
我有时会刷新并且有效。但有时这个错误会出现在控制台中。 这是API或我的代码的问题吗?
这是我的jsfiddle:http://jsfiddle.net/SQ3Bx/
<script>var myLatlng = new google.maps.LatLng(14.572388, 121.057784);
var marker;
var map;
function initialize() {
var styles = [
{
stylers: [
{ hue: "#319885" },
]
},
{
featureType: 'water',
elementType: 'geometry.fill',
stylers: [
{ color: '#3191fe' }
]
}
];
var styledMap = new google.maps.StyledMapType(styles,
{name: "Timeframe Style"});
var isDraggable = $(document).width() > 1000 ? true : false;
var mapOptions = {
draggable: isDraggable,
center: myLatlng,
zoom: 14,
scrollwheel: false,
mapTypeControlOptions: {
mapTypeIds: [google.maps.MapTypeId.SATELLITE, 'map_style']
}
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
image = 'img/map_marker.png';
marker = new google.maps.Marker({
map: map,
draggable: true,
animation: google.maps.Animation.DROP,
position: myLatlng,
icon: image
});
map.mapTypes.set('map_style', styledMap);
map.setMapTypeId('map_style');
google.maps.event.addListener(marker, 'click', toggleBounce);
}
function toggleBounce() {
if (marker.getAnimation() != null) {
marker.setAnimation(null);
} else {
marker.setAnimation(google.maps.Animation.BOUNCE);
}
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>