javascript - Google Maps not rendering at all -
i've worked maps , i've never faced issue map doesn't render @ all.
here's fiddle code implementation including request places api library
http://jsfiddle.net/newtt/ljn1n6nh/
here's code sample:
js:
function initialize() { var elem = document.getelementbyid('map-dire'); var map = new google.maps.map(elem, { maptypeid: google.maps.maptypeid.roadmap, }); } google.maps.event.adddomlistener(window, 'load', initialize());
it's simplest form of maps it's rendering grey/beige box , if click anywhere says uncaught typeerror: cannot read property 'x' of undefined
. understand error shows when dom element map isn't loaded. doesn't map trigger when window
element loaded?
**center , zoom required.**
try send latitude , longitude dynamically, giving hard coded values reference
function initialize() { var elem = document.getelementbyid('map-dire'); var mapoptions = { center: { lat: -34.397, lng: 150.644}, zoom: 8 }; var map = new google.maps.map(elem, mapoptions); map.setmaptypeid(google.maps.maptypeid.roadmap); } google.maps.event.adddomlistener(window, 'load', initialize());
your edited jsfiddle working if give zoom property like
function initialize() { var elem = document.getelementbyid('map-dire'); var map = new google.maps.map(elem, { maptypeid: google.maps.maptypeid.roadmap, center: { lat: -34.397, lng: 150.644},zoom: 8 }); } google.maps.event.adddomlistener(window, 'load', initialize());
Comments
Post a Comment