Article
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    API(s)
    Sencha-Touch
    Single Page App
    Bootstrap
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog

Home >> JQuery >> getCurrentPosition method in HTML5
getCurrentPosition method in HTML5
getCurrentPosition method in HTML5


by Awadhendra Tiwari on 7/30/2011 8:12:46 PM

Views: 8189       Comments: 0

getCurrentPosition method in HTML5

Gelocation is the identification of the real world geographic location of an internet-connected computer, mobile device, website visitor or other. IP address geolocation data can include information such as country, region, and city, postal/zip code, latitude, longitude and time zone..... Today most of the browsers and mobile devices support Geolocation API. The geolocation APIs work with a new property of the global navigator object i.e. Geolocation object which can be created as follows:

var location = navigator.geolocation;

Gelocation method:

·         getCurrentPosition()

·         watchposition()

·         clearWatch()

The getCurrentPosition method retrieves the current geographic location of the user. The location information is returned in a position object. In this article I am trying to show you that how we can find out the user geographic location.

Code:

<script type="text/javascript">

        function Location(position)//location function is defining with parameter

         {

            var latitude = position.coords.latitude; //Specifies the longitude estimate in decimal degrees. The value range is [-180.00, +180.00].

            var longitude = position.coords.longitude;

            document.getElementById("lati").innerHTML = latitude; //latitude value is defining in label element where id is lati

            document.getElementById("longi").innerHTML = longitude;

        }

        function findLocation()

        {

            if (navigator.geolocation)//checking browser compatibility

             {

                navigator.geolocation.getCurrentPosition(Location);//getCurrentPosition method retrieve the current geographic location of the user 

            }

        }

    </script>

</head>

<html>

<body>

    Latitude:<label id="lati"></label><br /><br />

    Longitude:<label id="longi"></label><br /><br />

    <input type="submit" onclick="findLocation();" value="Find Location" />

</body>

When button is clicked latitude and longituudeof the user  will show on page as shown below:

getCurrentPosition method in HTML5

Report Abuse Form
Reason:    
 

Title :
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
     
 
Latest Article by Awadhendra TiwariRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 5099
Advertisement
MindStick SurveyManager
Advertise with Us
  
Copyright © 2009 - 2014MindStick. All Rights Reserved.