Journey through javascript and angular js with the help of geolocation
-
Upload
francesco-iovine -
Category
Technology
-
view
675 -
download
4
Transcript of Journey through javascript and angular js with the help of geolocation
![Page 1: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/1.jpg)
Francesco Iovine & Marcos Lin @franciov & @marcoseu
Roma JS
31 Mar 2014
Journey through Javascript and AngularJS
with the help of geolocation :)
![Page 2: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/2.jpg)
https://developer.mozilla.org/en-US/Apps/Build/gather_and_modify_data/Plotting_yourself_on_the_map
Plotting yourself on the map
![Page 3: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/3.jpg)
OpenStreetMap
![Page 4: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/4.jpg)
Google Maps
![Page 5: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/5.jpg)
Hybrid Map
![Page 6: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/6.jpg)
http://dev.openlayers.org/apidocs
Open Layers
![Page 7: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/7.jpg)
https://developers.google.com/maps/documentation/javascript/
Google Maps Javascript API
![Page 8: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/8.jpg)
![Page 10: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/10.jpg)
Flow
![Page 11: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/11.jpg)
Maps
![Page 12: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/12.jpg)
Maps
function MapSwitcherViewController() {
/* DOM objects */this.openstreetmapViewControllerBox =
document.querySelector('#openstreetmap'); this.googlemapViewControllerBox =
document.querySelector('#googlemap');
this.hybridmapViewControllerBox = document.querySelector('#hybridmap');
![Page 13: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/13.jpg)
Maps
/* Manage target elements */window.onhashchange = function() {
self.performSwitch(window.location.hash);};
.actionBox .tabs ul li a:target {color: white;background: navy;
}
![Page 14: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/14.jpg)
Maps
window.mMapViewController =
MapViewControllerFactory.create({mapType: ...,mapId: ...
});
![Page 15: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/15.jpg)
Maps
JS.extend(OpenStreetMapViewController,MapViewController)
JS.extend(GoogleMapViewController,
MapViewController)
JS.extend(HybridMapViewController,
GoogleMapViewController)
![Page 16: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/16.jpg)
Search and Geolocation
![Page 17: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/17.jpg)
Search
var xhr = new XMLHttpRequest();xhr.open(
‘GET’, 'http://nominatim.openstreetmap.org/?q=' +
query + '&format=json', true);
xhr.send();
new google.maps.places.SearchBox
![Page 18: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/18.jpg)
navigator.geolocation.getCurrentPosition(successCallback, errorCallback, positionOptions
)
Geolocation
http://www.w3.org/TR/geolocation-API/
![Page 19: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/19.jpg)
PositionOptions.enableHighAccuracyPositionOptions.timeoutPositionOptions.maximumAge
Geolocation
function successCallback(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
// ...
}
![Page 21: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/21.jpg)
https://github.com/marcoslin/angularAMD
![Page 22: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/22.jpg)
AngularJS Quickie
![Page 23: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/23.jpg)
http://marcoslin.github.io/sample-geo-angular/
![Page 24: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/24.jpg)
Flow
![Page 25: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/25.jpg)
DOM
![Page 26: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/26.jpg)
Nested View<!– In body of index.html --><div ng-controller="MapController">
<div ng-view></div><div class="maps">
<div id="openstreetmap” ng-class="mapfs.OpenStreetMap_class"></div><div id="googlemap” ng-class="mapfs.GoogleMap_class"></div><div id="hybridmap” ng-class="mapfs.HybridMap_class"></div>
</div></div>
<!– In map.html --><div class="actionBox">
<div class="tabs"><ul><li><a ng-class="mapfs.OpenStreetMap_class"href="#/showOpenStreetMap">OpenStreetMap</a>
</li></ul></div>…
</div>
![Page 27: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/27.jpg)
var app = angular.module("geoapp", ['ngRoute']);
app.config(function ($routeProvider) { $routeProvider .when('/showOpenStreetMap', { templateUrl: "views/map.html", controller: "OpenStreetMapController"} ) ... .otherwise({redirectTo: '/showOpenStreetMap'}) ;});
Route Definition
![Page 28: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/28.jpg)
Controllers
![Page 29: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/29.jpg)
Nested Controllers// Parent Controller.controller('MapController’, function($scope, OpenStreetMap, …){
$scope.mapfs = { OpenStreetMap_class = “” };$scope.showMap = function (mapName) {
if ( mapName === "openstreetmap" ) {$scope.mapfs.OpenStreetMap_class = "active";
}};OpenStreetMap.initMap(“openstreetmap”);… ;
});
// Child Controller.controller(‘OpenStreetMapController’, function ($scope) {
$scope.showMap("openstreetmap");// $scope.mapfs.OpenStreetMap_class is now “active”
});
![Page 30: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/30.jpg)
Providers
![Page 31: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/31.jpg)
BaseGoogleMap.factory('BaseGoogleMap', function (…) {
var MapObject = function () { … };MapObject.prototype = {
initMap: function (mapId) { … };initSearchBox: function (inputId) { … };
};return MapObject;
});
.factory(‘GoogleMap’, function (BaseGoogleMap) {return new BaseGoogleMap();
});
.factory(‘HybridMap’, function (BaseGoogleMap) {var gmap = new BaseGoogleMap();gmap.initMap = function (mapId) { … };return gmap;
});
![Page 32: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/32.jpg)
AngularJS Promise.service('OpenStreetMap', function ($http, $q) {
this.search = function (query) {var url = “http://…” + query, d = $q.defer();
$http.get(url,function (response) {
// Update map with data from responsed.resolve(response);
},function (error) { d.reject(error); }
);
return d.promise;};
});
// Use Promise in ControllerOpenStreetMap.search(“Via del Corso”).then(function (data) {
// data is the same response object passed by $d.resolve});
![Page 33: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/33.jpg)
https://github.com/marcoslin/sample-geo-angular
![Page 34: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/34.jpg)
![Page 35: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/35.jpg)
http://addyosmani.com/resources/essentialjsdesignpatterns/book/
![Page 36: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/36.jpg)
http://www.flickr.com/photos/vividbreeze/480057824
![Page 37: Journey through javascript and angular js with the help of geolocation](https://reader033.fdocuments.in/reader033/viewer/2022060107/554a4927b4c9055a408b554f/html5/thumbnails/37.jpg)
Francesco Iovine & Marcos Lin @franciov & @marcoseu
Roma JS
31 Mar 2014
Journey through Javascript and AngularJS
with the help of geolocation :)