Reputation: 21
So I tried geocode but it can only find the users location based on ip addresses but I need the exact lat and long values of the user. Btw what is the accuracy of the ip address method.
Upvotes: 2
Views: 1637
Reputation: 4663
Ask the user on the client side for Geolocation permissions. You'll get the coordinates directly and you don't have to geocode anything. If the user doesn't give you the permission you shouldn't trying to locate them anyway.
Simple JS example:
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
// Do something with the coordinates
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
More information here.
Upvotes: 2
Reputation: 9700
You could use the Google GeoCode API but after 2000 requests, you would need to pay for it. This works on the idea that you have the users address or even just a post code (Zip code).
In terms of detecting location from IP, pretty hard if not impossible. You can usually get a broad location (City, County or State) but not the actual house or street etc.
Upvotes: 0