chrome.location
Description: |
Use the chrome.location API to retrieve the geographic location
of the host machine. This API is a version of the HTML Geolocation API
that is compatible with event pages.
|
Availability: |
Dev channel only.
|
Permissions: |
"location"
|
Overview
To start retrieving location information, you need to create a location watch
by calling location.watchLocation, passing in
the location watch details via the requestInfo
parameter:
chrome.location.watchLocation(name, requestInfo);
You also need to add a listener for the location.onLocationUpdate event. Chrome will fire this event after you create your location watch, and it will keep firing the event every time the geographic location of the host machine changes, until you call location.clearWatch.
Here's sample code to listen for location updates:
chrome.location.onLocationUpdate.addListener(function(position) { console.log(JSON.stringify(position)); });
Summary
Methods | |
---|---|
watchLocation −
chrome.location.watchLocation(string name, object requestInfo)
| |
clearWatch −
chrome.location.clearWatch(string name)
| |
Events | |
onLocationUpdate | |
onLocationError |
Methods
watchLocation
chrome.location.watchLocation(string name, object requestInfo)
Starts a location watching request. If there is another location watching request with the same name (or no name if none is specified), it will be cancelled and replaced by this request.
Parameters | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
string | name | Optional name to identify this request. Defaults to the empty string. | |||||||||
object | requestInfo |
Optional parameters for this request.
|
clearWatch
chrome.location.clearWatch(string name)
Ends a location watching request.
Parameters | ||
---|---|---|
string | name | Optional name to identify the request to remove. Defaults to the empty string. |
Events
onLocationUpdate
Fired when a location change is detected.
addListener
chrome.location.onLocationUpdate.addListener(function callback)
Parameters | |||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
function | callback |
The callback parameter should be a function that looks like this: function(object location) {...};
|
onLocationError
Fired when detecting location in not possible.
addListener
chrome.location.onLocationError.addListener(function callback)
Parameters | |||||
---|---|---|---|---|---|
function | callback |
The callback parameter should be a function that looks like this: function(string error) {...};
|