demo.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. !function ($) {
  2. $(function(){
  3. map = new GMaps({
  4. div: '#gmap_geocoding',
  5. lat: 37.77493,
  6. lng: -122.419416,
  7. zoom: 4
  8. });
  9. map.addMarker({
  10. lat: 37.77493,
  11. lng: -122.419416,
  12. title: 'Marker',
  13. infoWindow: {
  14. content: 'Info content here...'
  15. }
  16. });
  17. $('#geocoding_form').submit(function(e){
  18. e.preventDefault();
  19. GMaps.geocode({
  20. address: $('#address').val().trim(),
  21. callback: function(results, status){
  22. if(status=='OK'){
  23. var latlng = results[0].geometry.location;
  24. map.setCenter(latlng.lat(), latlng.lng());
  25. map.addMarker({
  26. lat: latlng.lat(),
  27. lng: latlng.lng()
  28. });
  29. }
  30. }
  31. });
  32. });
  33. $('#start_travel').click(function(e){
  34. $('#instructions').html('');
  35. e.preventDefault();
  36. map.setZoom(8);
  37. map.travelRoute({
  38. origin: [37.77493,-122.419416],
  39. destination: [37.339386,-121.894955],
  40. travelMode: 'driving',
  41. step: function(e){
  42. $('#instructions').append('<li><i class="fa-li fa fa-map-marker fa-lg icon-muted"></i> '+e.instructions+'</li>');
  43. $('#instructions li:eq('+e.step_number+')').delay(450*e.step_number).fadeIn(200, function(){
  44. map.setCenter(e.end_location.lat(), e.end_location.lng());
  45. map.drawPolyline({
  46. path: e.path,
  47. strokeColor: '#131540',
  48. strokeOpacity: 0.6,
  49. strokeWeight: 4
  50. });
  51. });
  52. }
  53. });
  54. });
  55. });
  56. }(window.jQuery);