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.

79 lines
2.5 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. angular.module('app.offerCar', ['pascalprecht.translate', 'ui-leaflet'])
  2. .controller('OfferCarCtrl', function($scope, $stateParams, $translate,
  3. $http, $filter) {
  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="offering";
  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. });
  40. };
  41. $scope.getGeo = function(){
  42. $scope.markers=[];
  43. console.log($scope.newtravel.from.name);
  44. console.log($scope.newtravel.to.name);
  45. $http.get('http://nominatim.openstreetmap.org/search?q=' + $scope.newtravel.from.name + '&format=json&limit=1')
  46. .then(function(data) {
  47. console.log(data);
  48. if(data.data[0])
  49. {
  50. $scope.newtravel.from.lat=data.data[0].lat;
  51. $scope.newtravel.from.long=data.data[0].lon;
  52. $scope.newtravel.from.name=data.data[0].display_name;
  53. $scope.markers.push({
  54. lat: Number(data.data[0].lat),
  55. lng: Number(data.data[0].lon),
  56. message: data.data[0].display_name
  57. });
  58. }
  59. $http.get('http://nominatim.openstreetmap.org/search?q=' + $scope.newtravel.to.name + '&format=json&limit=1')
  60. .then(function(data) {
  61. if(data.data[0])
  62. {
  63. $scope.newtravel.to.lat=data.data[0].lat;
  64. $scope.newtravel.to.long=data.data[0].lon;
  65. $scope.newtravel.to.name=data.data[0].display_name;
  66. $scope.markers.push({
  67. lat: Number(data.data[0].lat),
  68. lng: Number(data.data[0].lon),
  69. message: data.data[0].display_name
  70. });
  71. }
  72. });
  73. });
  74. };
  75. });