sets the value of an attribute class. thereafter any external class will be able to access this attribute. if you want you can also call a callback method to notify within another class that now has a variable value.
How to access Latitude and longitude geolocation using HTML5 outside of function
-
05-07-2023 - |
题
Can anyone suggest how to access latitude and longitude we get from HTML5 geolocation outside of getCurrentPosition
function? I don't want to show it on UI but need to send it to my spring controller. but can't access it outside the function.
Here is the code am referring too:
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
}
function showPosition(position) {
$scope.PostLoc = {latitude: null, longitude: null };
var lat = position.coords.latitude;
var longi = position.coords.longitude;
// var result = [lat, longi]; // it's an array
// return result;
}
I want this lat
and longi
variable to be access outside showPosition
function; but not successful, can anybody help, its already been few hours and am stucked. I want to send these to my controller and call google places api.
Thank you very much. please respond.
解决方案
不隶属于 StackOverflow