How can I catch only the latitude and longitude of return of this Function(Location)?

Asked

Viewed 530 times

0

<script type="text/javascript" src="//js.maxmind.com/js/apis/geoip2/v2.1/geoip2.js"></script>

<script type="text/javascript">

var onSuccess = function(location){

  var x = JSON.stringify(location, undefined, 3);
  document.write(x);
  return x;
};


var onError = function(error){
  alert(
      "Error:\n\n"
      + JSON.stringify(error, undefined, 3)
  );
};

geoip2.city(onSuccess, onError);


</script>

1 answer

-1

Try this:

function showPosition(position) {
   return position.coords.latitude + "," + position.coords.longitude;
}
  • Didn’t work :/

  • You are using a specific API, which is this

  • http://dev.maxmind.com/geoip/legacy/javascript/

  • In the api documentation it recommends using the function "geoip_latitude()" and "geoip_longitude()" both returning a decimal value

  • Ahh.. I now understand.. the function will return a JSON Object... Then you should use the variable of the callback in case x, it looks like this: x.latitude and x.longitude;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.