DZone
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
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Coding
  3. Languages
  4. HTML5 Geolocation: Problems and Solutions

HTML5 Geolocation: Problems and Solutions

John Esposito user avatar by
John Esposito
·
Jan. 02, 12 · Interview
Like (0)
Save
Tweet
Share
5.35K 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

  • Create a CLI Chatbot With the ChatGPT API and Node.js
  • Chaos Engineering Tutorial: Comprehensive Guide With Best Practices
  • Multi-Tenant Architecture for a SaaS Application on AWS
  • Integrate AWS Secrets Manager in Spring Boot Application

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • 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: