i want to get LatLng based on textbox value.
-
hello i want to get LatLng (in google map) based on the textbox value. what do i do? i have an error when run this cod: the error is:
Microsoft JScript runtime error: Object required
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false">
</script><script type="text/javascript">
var a=parseInt(document.getElementById("Text1").value);
var b=parseInt(document.getElementById("Text2").value);var myCenter=new google.maps.LatLng(a,b);
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,
animation:google.maps.Animation.BOUNCE
});marker.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script><input id="Text1" type="text" value="36"/>
<input id="Text2" type="text" value="59"/> -
hello i want to get LatLng (in google map) based on the textbox value. what do i do? i have an error when run this cod: the error is:
Microsoft JScript runtime error: Object required
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false">
</script><script type="text/javascript">
var a=parseInt(document.getElementById("Text1").value);
var b=parseInt(document.getElementById("Text2").value);var myCenter=new google.maps.LatLng(a,b);
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,
animation:google.maps.Animation.BOUNCE
});marker.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script><input id="Text1" type="text" value="36"/>
<input id="Text2" type="text" value="59"/>There are a few mistakes, 1. myCenter is not initialized 2. LatLng should be float type not integer type 3. there should be a function that is activated by say a button click in order to capture the new a and b values upon changes by the user 4. a and b have to be converted to latlng type 5. Spot the rest yourself from my demo code below:
<!DOCTYPE html>
<html>
<head>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false">
</script><script>
var a;
var b;
var map;var myCenter=new google.maps.LatLng(a,b);
function initialize()
{
a=parseFloat(document.getElementById("Text1").value);
b=parseFloat(document.getElementById("Text2").value);
var myCenter= new google.maps.LatLng(a, b);
var mapProp = {
center:myCenter,
zoom:8,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map=new google.maps.Map(document.getElementById("googleMap")
,mapProp);
var marker=new google.maps.Marker({
position:myCenter,
animation:google.maps.Animation.BOUNCE
});marker.setMap(map);
}
function updateLocation(){
a=parseFloat(document.getElementById("Text1").value);
b=parseFloat(document.getElementById("Text2").value);var latLng = new google.maps.LatLng(a, b); //create a latlng
map.panTo(latLng); //Make map global}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<input id="Text1" type="text" value="1.3520830"/>
<input id="Text2" type="text" value="103.819836"/>
<button onclick="updateLocation()">Update Location</button>
<div id="googleMap" style="width:800px;height:500px;"></div>
</body>
</html> -
There are a few mistakes, 1. myCenter is not initialized 2. LatLng should be float type not integer type 3. there should be a function that is activated by say a button click in order to capture the new a and b values upon changes by the user 4. a and b have to be converted to latlng type 5. Spot the rest yourself from my demo code below:
<!DOCTYPE html>
<html>
<head>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false">
</script><script>
var a;
var b;
var map;var myCenter=new google.maps.LatLng(a,b);
function initialize()
{
a=parseFloat(document.getElementById("Text1").value);
b=parseFloat(document.getElementById("Text2").value);
var myCenter= new google.maps.LatLng(a, b);
var mapProp = {
center:myCenter,
zoom:8,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map=new google.maps.Map(document.getElementById("googleMap")
,mapProp);
var marker=new google.maps.Marker({
position:myCenter,
animation:google.maps.Animation.BOUNCE
});marker.setMap(map);
}
function updateLocation(){
a=parseFloat(document.getElementById("Text1").value);
b=parseFloat(document.getElementById("Text2").value);var latLng = new google.maps.LatLng(a, b); //create a latlng
map.panTo(latLng); //Make map global}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<input id="Text1" type="text" value="1.3520830"/>
<input id="Text2" type="text" value="103.819836"/>
<button onclick="updateLocation()">Update Location</button>
<div id="googleMap" style="width:800px;height:500px;"></div>
</body>
</html>thank you very much
I say condolence for the suffering of martyrdom the prophet Mohammad and the Imam Hasan and the Imam Reza to all of the Muslims.:rose::rose: