GithubHelp home page GithubHelp logo

isabella232 / geolocation-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from w3c/geolocation-api

0.0 0.0 0.0 373 KB

W3C Geolocation API

Home Page: https://w3c.github.io/geolocation-api/

HTML 100.00%

geolocation-api's Introduction

Geolocation API

Welcome to the home of the W3C's Geolocation API!

Once a user grants permission, the Geolocation API provides access to geographical location information from device.

This repository is where the friendly folks of the Devices and Sensors Working Group maintain the specification.

Examples of usage

This HTTPs-only API exposes the navigator.geolocation object with a couple of useful methods:

  • .getCurrentPosition(successCallback, [errorCallback, options]) - "one shot" position request
  • .watchPosition(successCallback, [errorCallback, options]) - Watch a position and get notified of any changes.
  • .clearWatch(someId) - allows you to stop watching for location changes.

No location information is made available through this API without the user's permission.

.getCurrentPosition() method

Request the user's current location. If the user allows it, you will get back a position object.

navigator.geolocation.getCurrentPosition(position => {
  const { latitude, longitude } = position.coords;
  // Do something cool with latitude, longitude
});

.watchPosition() method

Request the ability to watch user's current location. If the user allows it, you will get back continuos updates of the user's position.

const watchId = navigator.geolocation.watchPosition(position => {
  const { latitude, longitude } = position.coords;
  // Do something cool with latitude, longitude
});

.clearWatch() method

Finally, stop watching the user's location.

navigator.geolocation.clearWatch(watchId);

More examples

The specification provides a great range of examples covering a diverse range of different use case.

geolocation-api's People

Contributors

anssiko avatar ashimura avatar autokagami avatar bathos avatar dontcallmedom avatar foolip avatar marcoscaceres avatar mkruisselbrink avatar plehegar avatar reillyeon avatar xfq avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.