javascript - Google maps not drawing the map on localhost -
am trying first current co-ordinates using navigator.geolocation , use latitude , longitude draw map.
but it's not showing map, blank white screen.
<html> <style type="text/css"> html{height: 100%} body{height: 100%; margin: 0; padding: 0} #map-canvas{height: 100%} </style> <script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script> <script> function getlocation() { if (navigator.geolocation){ navigator.geolocation.getcurrentposition(showposition); } else alert("geolocation not supported browser"); } function showposition(position) { coord = {}; coord.lat = position.coords.latitude; coord.longi = position.coords.longitude; initialize(coord); } function initialize(coord) { var map_canvas = document.getelementbyid('map_canvas'); var map_options = { center: new google.maps.latlng(coord.lat, coord.longi), zoom:8, maptypeid: google.maps.maptypeid.roadmap } var map = new google.maps.map(map_canvas, map_options); } google.maps.event.adddomlistener(window, 'load', getlocation); </script> <body> <div id="map_canvas" data-role="page"></div> </body> </html>
i going post http://jsfiddle.net/n5jqpo9u/1/ , don't see problem in code , mine works...
and right before press post button, realized, used map-canvas
rather map_canvas
css...
-
, _
:(
and way, can not location when run file using chrome. if operation timed out , or app has no permission location, display white page too. , should add error handling this:
http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_geolocation_error
Comments
Post a Comment