Advertisement
Guest User

gps

a guest
Jun 28th, 2016
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. <script>
  2. document.addEventListener("deviceready", onDeviceReady, false);
  3.  
  4. function onDeviceReady() {
  5. var yourLatLng;
  6. var resortLatLng;
  7. var directionsService=new google.maps.DirectionsService();
  8. $(this).ready(init);
  9. function init() {
  10. watchID=navigator.geolocation.getCurrentPosition(positionOK, positionError);
  11. }
  12. function positionOK(position) {
  13. yourLat=position.coords.latitude;
  14. yourLgt=position.coords.longitude;
  15. resortLat=40.121212;
  16. resortLng=40.101010;
  17. yourLatLng=new google.maps.LatLng(yourLat, yourLgt);
  18. resortLatLng=new google.maps.LatLng(resortLat, resortLng);
  19. var mapOptions={
  20. zoom:11,
  21. center:yourLatLng,
  22. mapType:google.maps.MapTypeId.ROADMAP
  23. }
  24.  
  25.  
  26. var map=new google.maps.Map(document.getElementById("map"), mapOptions);
  27. var myPosition=new google.maps.Marker({position:yourLatLng, map:map});
  28. var resortPosition=new google.maps.Marker({position:resortLatLng, map:map});
  29. directionsDisplay = new google.maps.DirectionsRenderer({
  30. 'map': map,
  31. 'preserveViewport': true,
  32. 'draggable': false
  33. });
  34. directionsDisplay.setPanel(document.getElementById("infomap"));
  35. google.maps.event.addListener(directionsDisplay, 'directions_changed', function() {
  36. if (currentDirections) {
  37. oldDirections.push(currentDirections);
  38. setUndoDisabled(false);
  39. }
  40. currentDirections = directionsDisplay.getDirections();
  41. });
  42. setUndoDisabled(false);
  43. percorso();
  44. }
  45. function setUndoDisabled(value) {
  46. // do something;
  47. }
  48. function percorso() {
  49. var start = yourLatLng;
  50. var end = resortLatLng;
  51. var request = {
  52. origin:start,
  53. destination:end,
  54. travelMode: google.maps.DirectionsTravelMode.DRIVING
  55. };
  56. directionsService.route(request, function(response, status) {
  57. if (status == google.maps.DirectionsStatus.OK) {
  58. directionsDisplay.setDirections(response);
  59. }
  60. })
  61. }
  62. function positionError(error) {
  63. alert("Error message");
  64. }
  65. }
  66. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement