问题
I have two pages. One is login page and in other page i am finding my location using Geolocation. But in login page I want to get that variable from location file and apply conditions on that variable.....
<script>
function displayLocation(latitude,longitude){
var request = new XMLHttpRequest();
var method = 'GET';
var url = 'http://maps.googleapis.com/maps/api/geocode/json? latlng='+latitude+','+longitude+'&sensor=true';
var async = true;
request.open(method, url, async);
request.onreadystatechange = function(){
if(request.readyState == 4 && request.status == 200){
var data = JSON.parse(request.responseText);
var address = data.results[1];
var check = address.formatted_address;
document.write(check);
}
};
request.send();
};
var successCallback = function(position){
var x = position.coords.latitude;
var y = position.coords.longitude;
displayLocation(x,y);
};
var errorCallback = function(error){
var errorMessage = 'Unknown error';
switch(error.code) {
case 1:
errorMessage = 'Permission denied';
break;
case 2:
errorMessage = 'Position unavailable';
break;
case 3:
errorMessage = 'Timeout';
break;
}
document.write(errorMessage);
};
var options = {
enableHighAccuracy: true,
timeout: 1000,
maximumAge: 0
};
navigator.geolocation.getCurrentPosition(successCallback,errorCallback,options);
When I call this file in my login file then it only displays location but login page contents disappears....Please help me
来源:https://stackoverflow.com/questions/32460280/i-want-to-get-location-in-a-variable-and-want-to-use-this-variable-to-apply-cond