Advertisement
Guest User

gps

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