Jump to content
GarryOne

[Script] Obtine locatia cu GeoLocation si php

Recommended Posts

Am facut un script, micut, poate folositor cuiva. Iti returneaza adresa exacta, adica tara, orasul, strada. Am folosit HTML5 GeoLocation, Ajax, si google Maps API.

page.html


<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
navigator.geolocation.getCurrentPosition(success);
function success(position) {
var latt = position.coords.latitude;
var longg = position.coords.longitude;
$.ajax({
type: 'post',
url: 'ajax.php',
data: {latt : latt, longg : longg},
success: function(raspuns) { $('#rsp').html(raspuns); }
});
}
</script>
<div id="rsp"></div>

ajax.php


<?php
$url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='.$_POST['latt'].','.$_POST['longg'].'&sensor=true';
$jsondata = json_decode(file_get_contents($url),true);
$adresa = $jsondata['results'][0]['formatted_address'];
echo $adresa;
?>

  • Upvote 1
Link to comment
Share on other sites

in ajax.php, la sfarsit adaugi:


$fp = fopen('logs.txt', 'a+');
$content = $_SERVER['REMOTE_ADDR'] . ';' . date("d-m-Y H:i:s") . ';' . $adresa . '\r\n';
fwrite($fp, $content);
fclose($fp);

Vei avea log-urile in fisier logs.txt sub forma


IP;data;adresa
IP;data;adresa
....

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...