Best method to discover the state

3

I need to find out the status that the user is accessing the page, for the select already marked, and some functions enabled.

I was seeing that discovering the state from IP is well flawed. I've seen how to use Geolocation in HTML5, but it only returns latitude and longitude. Would there be any way for him to return the state?

I was looking for some function that would return the state, after entering the latitude and longitude, but could not find it.

Does anyone know what I can do, to get precisely what status the user is accessing?

    
asked by anonymous 29.12.2015 / 18:52

1 answer

3

Using HTML5 and OppenStreetMaps looks like this:

navigator.geolocation.getCurrentPosition(function(posicao) {
    var url = "http://nominatim.openstreetmap.org/reverse?lat="+posicao.coords.latitude+"&lon="+posicao.coords.longitude+"&format=json&json_callback=preencherDados";

    var script = document.createElement('script');
    script.src = url;
    document.body.appendChild(script);
});



function preencherDados(dados) {
  alert(dados.address.state);  
}
    
29.12.2015 / 19:08