part 5 - html 5 drag and drop, geolocation
TRANSCRIPT
-
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
1/29
http://infobizzs.com/profile.phphttp://infobizzs.com/profile.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
2/29
Drag and drop is a very common feature.
It is when you "grab" an object and drag it to a different location.
In HTML5, drag and drop is part of the standard, and any
element can be draggable.
Internet Explorer 9+, Firefox, Opera, Chrome, and Safari support
drag and drop.
Note:Drag and drop does not work in Safari 5.1.2.
http://infobizzs.com/portfolio.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
3/29
http://infobizzs.com/portfolio.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
4/29
http://infobizzs.com/portfolio.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
5/29
Lets go through all the different parts of drag and drop
event.
First and foremost : Make the element draggable, by
setting the attribute as true.
http://infobizzs.com/portfolio.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
6/29
Now specify what should happen when the element is dragged.
In the example above, the ondragstart attribute calls a function,drag(event), that specifies what data to be dragged.
The dataTransfer.setData() method sets the data type and the
value of the dragged data :In this case, the data type is "Text" and the value is the id of thedraggable element ("drag1").
http://infobizzs.com/portfolio.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
7/29
The ondragover event specifies where the dragged data can bedropped.
By default, data/elements cannot be dropped in other elements.To allow a drop, we must prevent the default handling of theelement.
This is done by calling the event.preventDefault() method for theondragover event:
http://infobizzs.com/portfolio.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
8/29
When the dragged data is dropped, a drop event occurs.
In the example above, the ondrop attribute calls a function,drop(event) :
http://infobizzs.com/portfolio.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
9/29
When the dragged data is dropped, a drop event occurs.
In the example above, the ondrop attribute calls a function,drop(event) :
http://infobizzs.com/portfolio.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
10/29
Call preventDefault() to prevent the browser default handling ofthe data (default is open as link on drop).
Get the dragged data with the dataTransfer.getData("Text")method. This method will return any data that was set to the sametype in the setData() method.
The dragged data is the id of the dragged element ("drag1")
Append the dragged element into the drop element.
http://infobizzs.com/portfolio.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
11/29
http://infobizzs.com/portfolio.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
12/29
Geolocation is used to locate usersposition.
The HTML5 Geolocation API is used to get the geographicalposition of a user.
Since this can compromise user privacy, the position is not
available unless the user approves it.
Internet Explorer 9+, Firefox, Chrome, Safari and Opera supportGeolocation.
Note : Geolocation is much more accurate for devices with GPS,like iPhone.
http://infobizzs.com/profile.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
13/29
You can get userscurrent position using getCurrentPosition()method.
Lets see one example to get latitude and longitude of userscurrent position.
http://infobizzs.com/profile.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
14/29
http://infobizzs.com/profile.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
15/29
Check if Geolocation is supported.
If supported, run the getCurrentPosition() method. If not,display a message to the user
If the getCurrentPosition() method is successful, it returns a
coordinates object to the function specified in the parameter(showPosition)
The showPosition() function gets the displays the Latitude andLongitude.
http://infobizzs.com/profile.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
16/29
After submit the code. Now Click on Get location.
Now you can get the result as below :
http://infobizzs.com/profile.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
17/29
The second parameter of the getCurrentPosition() method isused to handle errors.
It specifies a function to run if it fails to get the user's location.
Letssee the example of error handling.
http://infobizzs.com/profile.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
18/29
http://infobizzs.com/profile.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
19/29
http://infobizzs.com/profile.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
20/29
http://infobizzs.com/profile.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
21/29
Error Codes : Permission denied - The user did not allow Geolocation Position unavailable - It is not possible to get the current
location Timeout - The operation timed out
http://infobizzs.com/profile.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
22/29
To display the result in a map, you need access to a map servicethat can use latitude and longitude, like Google Maps :
http://infobizzs.com/profile.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
23/29
http://infobizzs.com/profile.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
24/29
http://infobizzs.com/profile.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
25/29
In the example above we use the returned latitude and longitudedata to show the location in a Google map (using a static image).
http://infobizzs.com/profile.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
26/29
In the example above we use the returned latitude and longitudedata to show the location in a Google map (using a static image).
Location-specific Information :
This page demonstrated how to show a user's position on amap. However, Geolocation is also very useful for location-specificinformation. Examples :
Up-to-date local information Showing Points-of-interest near the user Turn-by-turn navigation (GPS)
http://infobizzs.com/profile.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
27/29
Property Description
coords.latitude The latitude as a decimal number
coords.longitude The longitude as a decimal number
coords.accuracy The accuracy of position
coords.altitude The altitude in meters above the meansea level
coords.altitudeAccuracy The altitude accuracy of position
The getCurrentPosition() method returns an object if it issuccessful. The latitude, longitude and accuracy properties are
always returned. The other properties below are returned ifavailable.
http://infobizzs.com/profile.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
28/29
Property Description
coords.headingThe heading as degrees clockwise
from North
coords.speed The speed in meters per second
timestamp The date/time of the response
http://infobizzs.com/profile.php -
7/27/2019 Part 5 - HTML 5 Drag and Drop, GeoLocation
29/29
Hope you note down and learn new things from this session. In the next session we will discuss about HTML 5 video andmore.
Thank You
http://infobizzs.com/