Reputation: 5183
I am building a mobile site in core php for a store which will show its nearest store on the basis of user's current location.
I am Currently getting current location on the basis of user's IP, But it dosnt seems to be accurate. So I want to know if i can envoke inbulit smart phone capabilties to get current location(remember its a mobile site not an app). I tried searching over stackoverflow Didnt get anything related.
Any link/advice in right direction would be great !
Upvotes: 0
Views: 913
Reputation: 471
I do not believe you can do this with PHP but HTML5 has built-in features for this.
Use of navigator.geolocation will give you the location of the user/phone with their permission.
navigator.geolocation.getCurentPosition(success, failure[, options]);
function success(location){
<!-- do stuff here if user gave permission -->
<!-- Latitude: location.coords.latitude -->
<!-- Longitude: location.coords.longitude -->
<!-- Accuracy in metters: location.coords.accuracy -->
}
function failure(){
<!-- User did not give permission, use failback code -->
}
Options is optional but can be very useful. You can set whether you require a high accuracy or not as well how old the location can be.
Upvotes: 2