Zubair Zahid
Zubair Zahid

Reputation: 228

Simple Google Map not working in JsFiddle

Can somebody please guide me how to create a basic Google Map in JsFiddle?

var myCenter=new google.maps.LatLng(51.508742,-0.120850);
function initialize(){
var mapProp = {
  center:myCenter,
  zoom:15,
  mapTypeId:google.maps.MapTypeId.ROADMAP
  };
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
var marker=new google.maps.Marker({
  position:myCenter,
  });
marker.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);

Link to JsFiddle https://jsfiddle.net/doublezed2/dvoav0ng/20/

Thanks, Zubair

Upvotes: 1

Views: 1517

Answers (1)

epoch
epoch

Reputation: 16595

Google is using its own event listener interface, while JSFiddle is trying to execute your code within a jQuery onLoad event handler

To make it work, you need to execute the map code directly in the <head>:

https://jsfiddle.net/dvoav0ng/24/

This is done by setting the option No wrap - in <head>

Upvotes: 3

Related Questions