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.

65 lines
2.0 KiB

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.createTravel =function(){
  20. $scope.newtravel.type="offering";
  21. $http({
  22. url: urlapi + 'travels',
  23. method: "POST",
  24. data: $scope.newtravel
  25. })
  26. .then(function(data) {
  27. console.log(data);
  28. window.location="#app/travels"
  29. },
  30. function(data) { // optional
  31. // failed
  32. console.log(data);
  33. });
  34. };
  35. $scope.getGeo = function(){
  36. $scope.markers=[];
  37. console.log($scope.newtravel.from.name);
  38. console.log($scope.newtravel.to.name);
  39. $http.get('http://nominatim.openstreetmap.org/search?q=' + $scope.newtravel.from.name + '&format=json&limit=1')
  40. .then(function(data) {
  41. $scope.newtravel.from.lat=data.data[0].lat;
  42. $scope.newtravel.from.long=data.data[0].lon;
  43. $scope.markers.push({
  44. lat: Number(data.data[0].lat),
  45. lng: Number(data.data[0].lon),
  46. message: data.data[0].display_name
  47. });
  48. $http.get('http://nominatim.openstreetmap.org/search?q=' + $scope.newtravel.to.name + '&format=json&limit=1')
  49. .then(function(data) {
  50. $scope.newtravel.to.lat=data.data[0].lat;
  51. $scope.newtravel.to.long=data.data[0].lon;
  52. $scope.markers.push({
  53. lat: Number(data.data[0].lat),
  54. lng: Number(data.data[0].lon),
  55. message: data.data[0].display_name
  56. });
  57. });
  58. });
  59. };
  60. });