Geolocation Test

back to ajnasz.hu


function getdata () {
  var geodata = document.getElementById('geodata');
  if(navigator.geolocation) {
    var gl = navigator.geolocation;
    var map = null;
    gl.getCurrentPosition(function(position) {
      // geodata.innerHTML = 'longitude: ' + position.coords.longitude + ', latitude: ' + position.coords.latitude;
      if(!map) {
        map = new google.maps.Map2(geodata);
      }
      var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
      map.setCenter(latLng, 14);
      var geocoder = new GClientGeocoder();
      geocoder.getLocations(latLng, function(response) {
        var posMarker = new google.maps.Marker(latLng, {title: 'your position is :' + position.coords.latitude + '(lat), ' +  position.coords.longitude + '(lng)'});
        map.addOverlay(posMarker);
        place = response.Placemark[0];
        posMarker.openInfoWindowHtml('<b>address:</b> ' + place.address);
        google.maps.Event.addListener(posMarker, 'click', function() {
          posMarker.openInfoWindowHtml('<b>address:</b>  ' + place.address);
        })
      });
    })
  } else {
    geodata.innerHTML = "not supported browser";
  }
};
google.setOnLoadCallback(getdata);