Created
April 30, 2016 05:22
-
-
Save mahedi2014/a71e1bbcbd69d4a9d491b0f289894d2d to your computer and use it in GitHub Desktop.
Display location on google map from address using javascript google map api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="map" style="width:70%;height:500px;"></div> | |
<h5>Tolarbag Mosque Road, Dhaka, Dhaka Division, Bangladesh</h5> | |
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> | |
<script> | |
var geocoder = new google.maps.Geocoder(); // initialize google map object | |
var address = "Tolarbag Mosque Road, Dhaka, Dhaka Division, Bangladesh"; | |
geocoder.geocode( { 'address': address}, function(results, status) { | |
if (status == google.maps.GeocoderStatus.OK) { | |
var latitude = results[0].geometry.location.lat(); | |
var longitude = results[0].geometry.location.lng(); | |
var myCenter=new google.maps.LatLng(latitude,longitude); | |
function initialize() | |
{ | |
var mapProp = { | |
center:myCenter, | |
zoom:7, | |
mapTypeId:google.maps.MapTypeId.ROADMAP | |
}; | |
var map=new google.maps.Map(document.getElementById("map"),mapProp); | |
var marker=new google.maps.Marker({ | |
position:myCenter, | |
}); | |
marker.setMap(map); | |
} | |
google.maps.event.addDomListener(window, 'load', initialize); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fantastic example, thank you... here's a thread with some similar examples:
https://stackoverflow.com/questions/6140303/google-maps-v3-how-to-center-using-an-address-on-initialize