DZone
Web Dev Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Web Dev Zone > HTML5 Geolocation: Problems and Solutions

HTML5 Geolocation: Problems and Solutions

John Esposito user avatar by
John Esposito
·
Jan. 02, 12 · Web Dev Zone · Interview
Like (0)
Save
Tweet
5.19K Views

Join the DZone community and get the full member experience.

Join For Free

JavaScript can ask browsers lots of questions, and IP addresses can (sort of) localize clients -- but only the new Geolocation API provides a standard language for browsers to tell webpages where the browser is physically located, in any way the browser chooses.

The concept of geolocation is simple ('where are you?'); but the W3C spec explicitly specifies that the API be 'agnostic to the underlying sources of location information' because the methods required to gather that information can become quite complex (GPS, cell triangulation, IP address, whatever), and can vary with device and circumstance

So browser manufacturers need to think hard about how to implement the Geolocation API. But, fortunately for web developers, the W3C's agnosticism requirement means that web apps are thoroughly abstracted from the actual geodata. This is particularly important because plenty of location-specific web apps might be used on multiple devices, from many places (think Foursquare, or Yelp), depending on whether the user is currently in place p or deciding whether (and how) to go there.

Recently .net magazine posted an extensive set of problems and solutions using the Geolocation API, excerpted from Chapter 8 of the HTML5 Cookbook by Christopher Schmitt and Kyle Simpson. If you're thinking about using the Geolocation API, this is an excellent place to start.

The excerpt/article begins with the basics ('getting basic geolocation data'), but includes many suggestions for practical use (for instance, IP-to-location fallback in JavaScript, if the browser doesn't support geolocation), useful related APIs (e.g., lat-long (what the Geolocation API returns) to Google Maps, and vice versa), directions from current location (also using Google -- though there are lots more APIs you might prefer for certain usecases, and more.

Extremely useful collection of libraries, APIs, snippets, and suggestions for anyone writing geolocation into a web app. Check it out here.

HTML

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Component Testing of Frontends: Karate Netty Project
  • Top 20 Git Commands With Examples
  • Implementing HIPAA Technical Safeguards in Your API Platform
  • Internal Developer Platform in Plain English

Comments

Web Dev Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo