Saturday, April 7, 2012

Disply the Google Map based on Longtitude and Latittude



href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css"
rel="stylesheet" type="text/css" />
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var geocoder;
var map;
var infowindow = new google.maps.InfoWindow();
var marker;
function initialize(argument1, argument2) {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(40.730885, -73.997383);
var myOptions = {
zoom : 8,
center : latlng,
mapTypeId : 'roadmap'
}
map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);

codeLatLng(argument1, argument2);
}

function codeLatLng(argument3,argument4) {

var lat ;
var lng ;
if(argument4==null){
lat=17.451998;
}
else{
lat=argument4;
}
if(argument3==null){
lng=78.393451;
}
else{
lng = argument3;
}
var latlng = new google.maps.LatLng(lat, lng);
geocoder.geocode({
'latLng' : latlng
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
map.setZoom(11);
marker = new google.maps.Marker({
position : latlng,
map : map
});
var address = (results[1].formatted_address);
//   document.getElementById('Address').value = results[1].formatted_address;
infowindow.setContent(results[1].formatted_address);

infowindow.open(map, marker);
} else {
alert("No results found");
}
} else {
alert("Geocoder failed due to: " + status);
}
});
}
</script>
</head>

<body
onload="initialize( 78.393451 , 17.451998 )">//this two values are longtitude and latittude value valus

No comments:

Post a Comment