You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.7 KiB

  1. angular.module('app.askForPackage', ['pascalprecht.translate', 'ui-leaflet'])
  2. .controller('AskForPackageCtrl', function($scope, $stateParams, $translate,
  3. $http, $filter, $ionicLoading) {
  4. $scope.newtravel={};
  5. $scope.newtravel.from={
  6. lat: 0,
  7. long:0
  8. };
  9. $scope.newtravel.to={
  10. lat: 0,
  11. long:0
  12. };
  13. $scope.center= {
  14. lat: 0,
  15. lng: 0,
  16. zoom: 1
  17. };
  18. $scope.markers=new Array();
  19. $scope.tiles= {
  20. url: "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
  21. options: {
  22. attribution: '<a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
  23. }
  24. };
  25. $scope.createTravel =function(){
  26. $scope.newtravel.type="package";
  27. $http({
  28. url: urlapi + 'travels',
  29. method: "POST",
  30. data: $scope.newtravel
  31. })
  32. .then(function(data) {
  33. console.log(data);
  34. window.location="#app/travels"
  35. },
  36. function(data) { // optional
  37. // failed
  38. console.log(data);
  39. $ionicLoading.show({ template: 'Complete all parameters first', noBackdrop: true, duration: 2000 });
  40. });
  41. };
  42. $scope.getGeo = function(){
  43. $scope.markers=[];
  44. console.log($scope.newtravel.from.name);
  45. console.log($scope.newtravel.to.name);
  46. $http.get('https://nominatim.openstreetmap.org/search?q=' + $scope.newtravel.from.name + '&format=json&limit=1')
  47. .then(function(data) {
  48. console.log(data);
  49. if(data.data[0])
  50. {
  51. $scope.newtravel.from.lat=data.data[0].lat;
  52. $scope.newtravel.from.long=data.data[0].lon;
  53. $scope.newtravel.from.name=data.data[0].display_name;
  54. $scope.markers.push({
  55. lat: Number(data.data[0].lat),
  56. lng: Number(data.data[0].lon),
  57. message: data.data[0].display_name
  58. });
  59. }
  60. $http.get('https://nominatim.openstreetmap.org/search?q=' + $scope.newtravel.to.name + '&format=json&limit=1')
  61. .then(function(data) {
  62. if(data.data[0])
  63. {
  64. $scope.newtravel.to.lat=data.data[0].lat;
  65. $scope.newtravel.to.long=data.data[0].lon;
  66. $scope.newtravel.to.name=data.data[0].display_name;
  67. $scope.markers.push({
  68. lat: Number(data.data[0].lat),
  69. lng: Number(data.data[0].lon),
  70. message: data.data[0].display_name
  71. });
  72. }
  73. });
  74. });
  75. };
  76. });