user location by IP [duplicate]

3

I would like to know a php library that would help me with the location of the user's IP access, well I found one on the internet and it worked well (did not exactly show the location) only 50 km of difference but at least know the city of access! Until here, this application uses the link to get the information, if, I load the page with the ip, it shows the data perfectly but if I put in to bring the information in the time when my Ajax is keeping those informed in the bank, it's a mistake! do not load the link to bring the ip info!

Does anyone know of any other method? library or article to help me? or better anyone know me explain why php with ajax does not load the link to the variables by?

echo "Geolocation results for {$geoplugin->ip}: <br />\n".
"City: {$geoplugin->city} <br />\n".
"Region: {$geoplugin->region} <br />\n".
"Area Code: {$geoplugin->areaCode} <br />\n".
"DMA Code: {$geoplugin->dmaCode} <br />\n".
"Country Name: {$geoplugin->countryName} <br />\n".
"Country Code: {$geoplugin->countryCode} <br />\n".
"Longitude: {$geoplugin->longitude} <br />\n".
"Latitude: {$geoplugin->latitude} <br />\n".
"Currency Code: {$geoplugin->currencyCode} <br />\n".
"Currency Symbol: {$geoplugin->currencySymbol} <br />\n".
"Exchange Rate: {$geoplugin->currencyConverter} <br />\n";

The class geoplugin already loads the ip altomaticamente so do not need to create variable for this, just ask the infomraçoes

    
asked by anonymous 12.01.2017 / 01:44

1 answer

3

Have you tried it this way? with geolocation .... in JS

/*início código de geolocalização*/
function GeoLocalizacao() {
    if (navigator.geolocation){//verificando se há suporte para API de     Geolocalização
    navigator.geolocation.getCurrentPosition(locSucesso, erro);
    } else {
       $('#status').text('Seu browser não suporta geolocalização!');
    }
}

If you are ok .. just show the data on the map

function locSucesso(position) {
var latlngGeo = new google.maps.LatLng(position.coords.latitude,position.coords.longitude); //pegando localização do usuário
var myOptions = {//opções do mapa
    zoom: 15, //configuração da proximidade de visualização do mapa quando iniciado
    mapTypeId: google.maps.MapTypeId.ROADMAP, //tipo do mapa (ROADMAP --> normal, default 2D map)
    center: latlngGeo
};

map = new google.maps.Map(document.getElementById("mapa"), myOptions);
geocoder = new google.maps.Geocoder();

marker = new google.maps.Marker({
    map: map,
    draggable: true,
    title:"Você está aqui!" //texto quando usuário passar mouse por cima do marcador
});
marker.setPosition(latlngGeo);

var infowindow = new google.maps.InfoWindow({
    content: 'Você está aqui!' //mostrar texto quando usuário clicar no marcador
});

... I tried sending the data through a form .. that is in my view I created a form with hidden fields and with the geolocation result I put the values lat and long (through jQuery) in the form. .. and with that you can send the form via ajax (json) to the controller and treat them for sending to the bank.

    
28.02.2017 / 15:51