开发者

Storing HTML5 Geolocation information in MySQL

I'v开发者_如何学JAVAe been experimenting with a simple project that essentially just stores the number of visits to the sites, along with the latitude / longitude of the user (it's mainly for people visiting via the iPhones Safari browser).

I've managed to store the 'clicks' to the page via PHP / MySQL, and I can display the users lat / long via the navigator.geolocation object in Javascript, but I have no idea how I can then store that (I'm fairly new at this!).

I appreciated that JavaScript is client-side and PHP is server-side, so I presume I need to somehow pass the returned values of my Javascript back to the PHP code somehow?

Thanks for any advice!


I've not used the navigator.geolocation object, but you should be able to send what it returns to an external page using AJAX.

<script>
var data = 'something-here'; // the result of your geolocation call
$.ajax({
    type: 'POST',
    url: 'http://yourdomain.com/storeLatLngInDb.php',
    data: data
});
</script>

The above is an example written on top of the jQuery framework.


You presume well. You can either put them in hidden fields in a form and ask user to press the button to send data to serve, or you can initiate AJAX call.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜