Google Map lng + lat to hidden field not working

Posted by user547794 on Stack Overflow See other posts from Stack Overflow or by user547794
Published on 2010-12-26T00:37:08Z Indexed on 2010/12/26 0:54 UTC
Read the original article Hit count: 192

Filed under:
|

Hello,

I am trying to get Marker data into hidden fields on my form. I'm not sure why this isn't working, it must be something in my js syntax:

var initialLocation;
var siberia = new google.maps.LatLng(60, 105);
var newyork = new google.maps.LatLng(40.69847032728747, -73.9514422416687);
var browserSupportFlag =  new Boolean();




function initialize() {
  var myOptions = {
    zoom: 6,
    mapTypeId: google.maps.MapTypeId.HYBRID
  };
  var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    myListener = google.maps.event.addListener(map, 'click', function(event) {
    placeMarker(event.latLng), google.maps.event.removeListener(myListener);

  });





  // Try W3C Geolocation (Preferred)
  if(navigator.geolocation) {
    browserSupportFlag = true;
    navigator.geolocation.getCurrentPosition(function(position) {
      initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
      map.setCenter(initialLocation);
    }, function() {
      handleNoGeolocation(browserSupportFlag);
    });
  // Try Google Gears Geolocation
  } else if (google.gears) {
    browserSupportFlag = true;
    var geo = google.gears.factory.create('beta.geolocation');
    geo.getCurrentPosition(function(position) {
      initialLocation = new google.maps.LatLng(position.latitude,position.longitude);
      map.setCenter(initialLocation);
    }, function() {
      handleNoGeoLocation(browserSupportFlag);
    });
  // Browser doesn't support Geolocation
  } else {
    browserSupportFlag = false;
    handleNoGeolocation(browserSupportFlag);
  }

  function handleNoGeolocation(errorFlag) {
    if (errorFlag == true) {
      alert("Geolocation service failed.");
      initialLocation = newyork;
    } else {
      alert("Your browser doesn't support geolocation. We've placed you in Siberia.");
      initialLocation = siberia;
    }
  }
  function placeMarker(location) {
  var marker = new google.maps.Marker({
      position: location, 
      map: map,
      draggable: true
  });

  map.setCenter(location);


}
}

var lat = latlng.lat();
  var lng = latlng.lng();
document.getElementById("t1").value=lat;
document.getElementById("t2").value=lng;

 <input type="hidden" name="lat" id="t1">
    <input type="hidden" name="long" id="t2">

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about google-maps