How to get user location in javascript (YUI)

Hey Guys ,
Here is a simple code to get User's Location (lat and lan) in javascript using YUI.

Why Not to use HTML5?
Html5 is not yet supported by many browsers and have no fall back. YUI implementation falls back up to ip based location.

<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Location using YUI (with fallback)</title>
<script src=""></script>
YUI({gallery: 'gallery-2011.05.12-13-26'}).use('gallery-geo', function(Y) {
if (response.success){
var e=document.getElementById('geolocation');
e.innerHTML="Your Location :"+response.coords.latitude+","+response.coords.longitude;
<div id="geolocation" >


Note: If you host the file locally, e.g. file:// , it might not work due to security issues. 

No comments:

Post a Comment

Your comment will inspire me, Please leave your comment