
Geolocation/Drag & Drop
Presentation
•
Computers
•
University
•
Hard
Gerald Albano
Used 10+ times
FREE Resource
22 Slides • 0 Questions
1
Geolocation/Drag & Drop
2
3
4
5
6
Geolocation Methods
The geolocation object provides the following methods −
7
Geolocation getCurrentPosition()
The getCurrentPosition method retrieves the current geographic location of the device. The location is expressed as a set of geographic coordinates together with information about heading and speed. The location information is returned in a Position object.
8
Following is a sample code to use any of the above method −
function getLocation() {
var geolocation = navigator.geolocation;
geolocation.getCurrentPosition(showLocation, errorHandler);
}
Here showLocation and errorHandler are callback methods which would be used to get actual position as explained in next section and to handle errors if there is any.
9
Location Properties
Geolocation methods getCurrentPosition() and getPositionUsingMethodName() specify the callback method that retrieves the location information. These methods are called asynchronously with an object Position which stores the complete location information.
The Position object specifies the current geographic location of the device. The location is expressed as a set of geographic coordinates together with information about heading and speed.
The following table describes the properties of the Position object. For the optional properties if the system cannot provide a value, the value of the property is set to null.
10
Property/Type
Description
coords / objects -Specifies the geographic location of the device. The location is expressed as a set of geographic coordinates together with information about heading and speed.
coords/latitude -Number Specifies the latitude estimate in decimal degrees. The value range is [-90.00, +90.00].
coords/longitude- Number Specifies the longitude estimate in decimal degrees. The value range is [-180.00, +180.00].
coords/altitude- Number [Optional] Specifies the altitude estimate in meters above the WGS 84 ellipsoid.
11
coords/accuracy- Number [Optional] Specifies the accuracy of the latitude and longitude estimates in meters.
coords/altitudeAccuracy -Number [Optional] Specifies the accuracy of the altitude estimate in meters.
coords/heading- Number [Optional] Specifies the device's current direction of movement in degrees counting clockwise relative to true north.
coords/speed- Number [Optional] Specifies the device's current ground speed in meters per second.
timestamp /date- Specifies the time when the location information was retrieved and the Position object created.
12
Following is a sample code which makes use of Position object. Here showLocation method is a callback method −
function showLocation( position ) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
...
}
13
Geolocation watchPosition()
The watchPosition method retrieves periodic updates about the current geographic location of the device. The location is expressed as a set of geographic coordinates together with information about heading and speed.
The location information is returned in a Position object. Each update returns a new Position object
14
Geolocation clearWatch()
The clearWatch method cancels an ongoing watchPosition call. When cancelled, the watchPosition call stops retrieving updates about the current geographic location of the device.
SyntaxHere is the syntax of this method −
clearWatch(watchId);
15
Handling Errors
Geolocation is complicated, and it is very much required to catch any error and handle it gracefully.
The geolocations methods getCurrentPosition() and watchPosition() make use of an error handler callback method which gives PositionError object. This object has following two properties −
16
Property / Type / Description
code / Number - Contains a numeric code for the error.
message / String -Contains a human-readable description of the error.
17
The following table describes the possible error codes returned in the PositionError object.
18
Code / Constant / Description
0 / UNKNOWN_ERROR - The method failed to retrieve the location of the device due to an unknown error.
1 / PERMISSION_DENIED - The method failed to retrieve the location of the device because the application does not have permission to use the Location Service.
2 / POSITION_UNAVAILABLE - The location of the device could not be determined.
3 / TIMEOUT - The method was unable to retrieve the location information within the specified maximum timeout interval.
19
Following is a sample code which makes use of PositionError object. Here errorHandler method is a callback method −
function errorHandler( err ) {
if (err.code == 1) {
// access is denied
}
...
}
20
Position Options
Following is the actual syntax of getCurrentPosition() method −
getCurrentPosition(callback, ErrorCallback, options)
Here third argument is the PositionOptions object which specifies a set of options for retrieving the geographic location of the device.
Following are the options which can be specified as third argument
21
Property / Type / Description
enableHighAccuracy / Boolean - Specifies whether the widget wants to receive the most accurate location estimate possible. By default this is false.
timeout / Number - The timeout property is the number of milliseconds your web application is willing to wait for a position.
maximumAge / Number - Specifies the expiry time in milliseconds for cached location information.
22
Following is a sample code which shows how to use above mentioned methods −
function getLocation() {
var geolocation = navigator.geolocation;
geolocation.getCurrentPosition(showLocation, errorHandler, {maximumAge: 75000});
}
Geolocation/Drag & Drop
Show answer
Auto Play
Slide 1 / 22
SLIDE
Similar Resources on Wayground
14 questions
Electron Math
Presentation
•
9th - 12th Grade
14 questions
HEALTH PROBLEMS
Presentation
•
University
18 questions
AI for Teach session 2
Presentation
•
University
16 questions
Simple Present
Presentation
•
University
16 questions
SAD-Chapter 2- PM
Presentation
•
University
17 questions
ITOM Topic 10 & 11
Presentation
•
University
14 questions
Quantifiers
Presentation
•
University
14 questions
Discuss career choices
Presentation
•
University
Popular Resources on Wayground
6 questions
Secondary Safety Quiz
Presentation
•
9th - 12th Grade
10 questions
Afterschool Activities & Sports
Quiz
•
6th - 8th Grade
19 questions
ROAR Week 2026
Quiz
•
9th - 12th Grade
20 questions
Lab Safety Quiz
Quiz
•
6th Grade
15 questions
Cool Tool:Chromebook
Quiz
•
6th - 8th Grade
22 questions
would you rather
Quiz
•
3rd - 11th Grade
21 questions
Continents and Oceans
Quiz
•
6th Grade
20 questions
Parts of Speech
Quiz
•
5th Grade
Discover more resources for Computers
12 questions
Academic Integrity
Presentation
•
University
20 questions
IR Writing 201
Quiz
•
University
20 questions
Disney Trivia
Quiz
•
University
40 questions
Famous Logos
Quiz
•
7th Grade - University
4 questions
Benefits of Saving
Quiz
•
5th Grade - University
25 questions
USCB Policies and Procedures
Quiz
•
University
18 questions
Parent Functions
Quiz
•
9th Grade - University
20 questions
Empirical Rule Homwwork
Quiz
•
10th Grade - University