I need to implement on my php page map. I have container <div id="map"></div>
which is inside other div, and I put this code inside <head>
tag but it doesn’t show at all. Can anybody help me?
<script type="text/javascript" src="javascript/jquery-1.4.3.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
(function() {
window.onload = function() {
var mapDiv = document.getElementById('map');
var latlng = new google.maps.LatLng(37.09, -95.71);
var options = {
center: latlng,
zoom: 4,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(mapDiv, options);
}
})();
</script>
Check the validity of your HTML and the doctype declaration. It has been an issue on several Google Maps I’ve setup.
See this
Your code does work for me even though the last line, when you close that anonymous function, gave me an error like you were using some illegal character, so I had to retype it. Once I did, it worked perfectly showing a road map of all of the United States.
Other than that possible illegal character you could also try:
- giving your #map element a height and width or else it won’t be visible.
- putting all your javascript inside $(document).ready() so it’s only execute when the document is ready.
- you say that you include your scripts in the head tag of your document, but maybe you should try putting them at the end of your body to speed up loading.
Hope that helps.
If any one using google map code from javascript or jquery or any language,
He/She should use for local host https://localhost/test/ or in server https://example.com.
Means use secure url like https