I am creating a web app that uses the Google Maps API to display a map. When I reload the page it does not initialize the map where my coordinates tell it to and is "fuzzy". Once I zoom out using the toolbar on the left and zoom back in everything is fine. Here is my code:
<!DOCTYPE html>
<html>
<head>
<title>Google Maps JavaScript</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta charset="UTF-8">
<style type="text/css">
html, body, #map_canvas {
margin: 0;
padding: 0;
height: 50%;
}
</style>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var map;
function initialize() {
var myOptions = {
zoom: 14,
center: new google.maps.LatLng(2.3584170693, -71.065063476),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map_canvas'),
myOptions);
var bikeLayer = new google.maps.BicyclingLayer();
bikeLayer.setMap(map);
var marker = new google.maps.Marker({
position: new google.maps.LatLng(42.346872819794896, -71.06643676757812),
map: map,
title: 'REPORT'
});
var marker = new google.maps.Marker({
position: new google.maps.LatLng(42.363363955820496, -71.08978271484375),
map: map,
title: 'REPORT'
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map_canvas" style="width: 90%; height: 300%"></div>
</body>
</html>
I noticed your markers are around (42.3, -71), Boston, but the map's center as written in the options, is missing a '4' and sending the initial location to Colombia at (2.3, -71).
About the fuzzyness, could it just be the bicycling layer taking a while to load? I am unable to reproduce this effect.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.