Here is my code
- Code: Select all
<script type="text/javascript">
var geocoder;
var myLatlng;
var marker;
var infowindow;
var map;
function codeLatLng() {
myLatlng = new google.maps.LatLng(40.730885,-73.997383);
geocoder = new google.maps.Geocoder();
var myOptions = {
center: myLatlng,
zoom: 4,
panControl: true,
zoomControl: true,
mapTypeControl: true,
scaleControl: true,
streetViewControl: true,
overviewMapControl: true,
mapTypeId: google.maps.MapTypeId.HYBRID
};
// Defines a single map for the page
map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var input = document.getElementById("latlng").value;
var latlngStr = input.split(",",2);
var lat = parseFloat(latlngStr[0]);
var lng = parseFloat(latlngStr[1]);
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({
map:map,
animation: google.maps.Animation.BOUNCE,
position: myLatlng,
title:"YOUR LOCATION"
});
var contentString ="You will be here";
infowindow = new google.maps.InfoWindow({
content: contentString
});
infowindow.setContent(results[1].formatted_address+"<br>"+contentString);
//used + for adding multiple values
infowindow.open(map, marker);
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
} else {
alert("No results found");
}
} else {
alert("Geocoder failed due to: " + status);
}
});
}
</script>
</head>
<body bgcolor="black" onload="codeLatLng()">
<div>
<input id="latlng" type="textbox" value="40.730885,-73.997383">
</div>
<div id="map_canvas" style="width:709px; height:416px; position:absolute; left:236px; top:86px; z-index:1;"></div>
</body>
What I want to do is put the value of var myLatlng into var input
for ref [myLatlng = new google.maps.LatLng(40.730885,-73.997383);]
For this I am simply putting var input =myLatlng; but this is not working var input is only accept string value from the div tag. How do I put the value of input variable through javascript. Please help me out. I don't know how to fix this. Thanks