These forums are currently read-only due to receiving more spam than actual discussion. Sorry.

It is currently Sat Dec 02, 2017 4:12 pm Advanced search

Html 5 Geododing

If you are stuck or have questions regarding HTML or other Web technologies, ask your questions here. No question too dumb!

Html 5 Geododing

Postby Shivang » Sun Jul 08, 2012 2:54 pm

I am kinda stuck in my code.

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
Shivang
<h6>
 
Posts: 1
Joined: Sun Jul 08, 2012 2:51 pm

Re: Html 5 Geododing

Postby zcorpan » Mon Jul 09, 2012 10:52 am

Code: Select all
document.getElementById("latlng").value = myLatlng

If I understand what you mean.

You can assign "document.getElementById("latlng")" to a variable and do foo.value = myLatlng, but you can't assign "document.getElementById("latlng").value" to a variable and do foo = myLatlng since that will just change the variable foo, not the value of the input element.
zcorpan
<article>
 
Posts: 807
Joined: Tue Feb 06, 2007 8:29 pm
Location: Sweden


Return to Help & Advice

Who is online

Users browsing this forum: No registered users and 1 guest