1

Hello I am using the following GeoLocation function to get the location of a visitor

function success(position) {
  var s = document.querySelector('#location');

  if (s.className == 'success') {
    return;
  }

  s.value = "found you!";
  s.className = 'success';

  var mapcanvas = document.createElement('div');
  mapcanvas.id = 'mapcanvas';
  mapcanvas.style.height = '200px';
  mapcanvas.style.width = '380px';

  document.querySelector('article').appendChild(mapcanvas);

  var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
  var myOptions = {
    zoom: 15,
    center: latlng,
    mapTypeControl: false,
    navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  var map = new google.maps.Map(document.getElementById("mapcanvas"), myOptions);

  var marker = new google.maps.Marker({
      position: latlng, 
      map: map, 
      title:"You are here!"
  });
}

function error(msg) {
  var s = document.querySelector('#status');
  s.innerHTML = typeof msg == 'string' ? msg : "failed";
  s.className = 'fail';

  // console.log(arguments);
}

if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(success, error);
} else {
  error('not supported');
}

As you see it write in the field the value "found you!" when the process is successful.

Now what I need instead of writing "found you!" I need to write the location of the visitor.

So if the member is in Rome, it will write "Rome, Italy"

How do I achieve it?

Thanks for your help!!!

1 Answer 1

1

You want geocoding (or reverse geocoding). I wrote a short overview here on my support forum. See the links near the end of the post.

A more involved example: my tutorial using google maps, jquery, markers and geocoding, includes source for getting full address from lat/lng coords.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.