• Home
  • Trace mobile number (From India)
  • Entertainment
  • SiteMap
  • Home
  • ASP.NET
  • C#
  • BLOGGING
  • SQL SERVER
  • FACEBOOK
  • Entertainment

The Geolocation API provides a method to locate the user’s exact  position. This is useful in a number of ways ranging from providing a user with location specific information to providing route navigation.Internet Explorer 9, Firefox, Chrome, Safari and Opera support Geolocation.

A number of different sources are used to attempt to obtain the user’s location, and each has their own varying degree of accuracy. A desktop browser is likely to use WiFi (accurate to 20m) or IP Geolocation which is only accurate to the city level and can provide false positives. Mobile devices tend to use triangulation techniques such as GPS (accurate to 10m and only works outside), WiFi and GSM/CDMA cell IDs (accurate to 1000m).

Use the getCurrentPosition() method to get the user's position.

The example below is a simple Geolocation example returning the latitude and longitude of the user's position:


<script>

var MyLoc=document.getElementById("demo");

function getUserLocation()

  {

  if (navigator.geolocation) //This will check if browser support geolocation.
   {
    navigator.geolocation.getCurrentPosition(showPosition);
   }
  else
  {
  MyLoc.innerHTML="Geolocation is not supported by this browser.";
  }
 
  }

  function showPosition(position)
  {
  MyLoc.innerHTML="Latitude: " + position.coords.latitude +
  "<br>Longitude: " + position.coords.longitude;
  }
</script>



The above function first Check if Geolocation is supported by browser If supported, run the getCurrentPosition() method. If Geolocation is supported by browser, display a message to the user .If the getCurrentPosition() method is successful, it returns a coordinates object to the function specified in the parameter ( showPosition ) and The showPosition() function gets the displays the Latitude and Longitude.

Displaying the Result in a Map

To display the result in a map, you need access to a map service that can use latitude and longitude, like Google Maps. Change the showPosition method like this .



<script>

var MyLoc=document.getElementById("demo");

function getUserLocation()

  {

  if (navigator.geolocation) //This will check if browser support geolocation.
   {
    navigator.geolocation.getCurrentPosition(showPosition);
   }
  else
  {
  MyLoc.innerHTML="Geolocation is not supported by this browser.";
  }
 
  }


function showPosition(position)

{

var latlon=position.coords.latitude+","+position.coords.longitude;

var img_url="http://maps.googleapis.com/maps/api/staticmap?center="

+latlon+"&zoom=14&size=400x300&sensor=false";

document.getElementById("mapholder").innerHTML="<img src='"+img_url+"'>";

}

</script>




This script will display  location in map.
Newer Posts Older Posts Home

Most Read

  • How to Capitalize the First Letter of All Words in a string in C# ?
  • keyboard shortcuts For Windows
  • List Of Best Free WordPress Plugins : 2012
  • Read Write XML Data-Read Write XML File Using C#, VB.NET In Asp.Net
  • How to Shake Internet Explorer - Javascript Code
  • How to Choose a Nice Topic for your Blog .
  • Free Search Engine Submission List ,search engine optimization
  • Number validation in Textbox of ASP.NET Using Regular Expression validator
  • Javascript:Percentage Gain Javascript Calculator
  • .Net Interview Questions and Answers on OOPS | OOPS Frequently Asked Questions
Google
Custom Search Bloggers - Meet Millions of Bloggers

Join Us On FaceBook

  • Recent Posts
  • Comments

All Topics

  • ►  2014 (10)
    • ►  January (10)
  • ►  2013 (14)
    • ►  October (1)
    • ►  April (2)
    • ►  March (11)
  • ▼  2012 (142)
    • ►  December (25)
    • ▼  October (1)
      • HTML5 Geolocation | Using geolocation in HTML5
    • ►  September (9)
    • ►  August (2)
    • ►  July (7)
    • ►  June (2)
    • ►  April (5)
    • ►  March (27)
    • ►  February (27)
    • ►  January (37)
  • ►  2011 (23)
    • ►  December (3)
    • ►  November (6)
    • ►  October (12)
    • ►  September (2)
  • ►  2009 (1)
    • ►  June (1)

Tips & Tricks

  • What is good One Blog and Many Categories, or Many Blogs with One Categories?
  • Adding Twitter tweet button to each Blogger posts.
  • How to Choose a Nice Topic for your Blog .
  • Embedding YouTube Videos ,movie in your blog
  • Facebook iFrame Apps – Getting Rid of Scrollbars
  • Facebook Analytics:How to Set Up Your Website or Blog with Facebook Insights for Domains
  • How To Add Perfect Share Box to Blogger
  • Blogger Free Images Hosting Tip,Free unlimited bandwidth image hosting for Blogger blogs
  • Add “Link to this post” codes below Each blogger posts
  • Free Search Engine Submission List ,search engine optimization
  • Adsense Tips for Maximum CTR
  • List Of Best Free WordPress Plugins : 2012
2012 tectopix. All rights reserved.
Designed by tectopix