angular.module('starter.services', [])

.factory('mapService', function(){
	
	var map = null;
	var routeElements = [];
	
	var initMap = function(){
		var options = {timeout: 10000, enableHighAccuracy: true};
	 
	    var latLng = new google.maps.LatLng(51.962022, 7.624095);
	 
	    var mapOptions = {
	      center: latLng,
	      zoom: 15,
	      mapTypeId: google.maps.MapTypeId.ROADMAP
	    };
	 
	    map = new google.maps.Map(document.getElementById("map"), mapOptions);
	    
	    var longpress = false;

    	google.maps.event.addListener(map,'click', function (event) {
        	    (longpress) ? setMarkerForRouting(event.latLng) : null;
        });

	    google.maps.event.addListener(map, 'mousedown', function(event){
      	          start = new Date().getTime();           
        });

    	google.maps.event.addListener(map, 'mouseup', function(event){
                end = new Date().getTime();
                    longpress = (end - start < 500) ? false : true;         

        });
	    
	    return map;
	};
	
 	var setMarkerForRouting = function(location){	
 		if (routeElements.length < 2){
	 		var marker = new google.maps.Marker({
			    position: new google.maps.LatLng(location.lat(), location.lng()),
			    draggable: true			  	
			});
			routeElements.push(marker);
			for (marker in routeElements){
				routeElements[marker].setMap(map);
			}
			if (routeElements.length == 2) routing();
		}else{
			deleteRoutingElements();
		}
 	};
 	
 	var deleteRoutingElements = function(){
 		for (elem in routeElements){
 			routeElements[elem].setMap(null);
 		}
 		routeElements = new Array();
 	};
 	
 	var routing = function(){
 		var directionsService = new google.maps.DirectionsService();	
		var request = {
		    origin: routeElements[0].position,
		    destination: routeElements[1].position,
		    travelMode: google.maps.TravelMode.WALKING,
		};		
		directionsService.route(request, function(response, status) {
		  if (status == google.maps.DirectionsStatus.OK) {
		    var route = new google.maps.Polyline({path:response.routes[0].overview_path});
		    route.setMap(map);
		    routeElements.push(route);
		  }
		});			
 	};
	
	return {
		initMap: initMap
	};
});
@@ -470,24 +470,134 @@
 ions);%0A%09    
+console.log(navigator.geolocation.getCurrentPosition(function(position)%7B%0A%09    %09console.log(position)%0A%09    %7D));
 %0A%09    var lo
@@ -1110,34 +1110,708 @@
 %7D);%0A
-%09    %0A%09    return map;%0A%09%7D;
+        %0A        var geoloccontrol = new klokantech.GeolocationControl(map, map.getZoom());%0A%09    %0A%09    return map;%0A%09%7D;%0A%09%0A%09var Latitude = undefined;%0A%09var Longitude = undefined;%0A%0A%09document.addEventListener(%22deviceready%22, onDeviceReady, false);%0A    function onDeviceReady() %7B%0A%0A    var onSuccess = function(position) %7B%0A    %09Latitude = position.coords.latitude;%0A    %09Longitude = position.coords.longitude;%0A    %09console.log(position.coords)%0A    %09map.setCenter(%7Blat:Latitude, lng:Longitude%7D);%0A    %7D;%0A%0A    function onError(error) %7B%0A        alert('code: '    + error.code    + '%5Cn' +%0A              'message: ' + error.message + '%5Cn');%0A    %7D%0A%0A%09navigator.geolocation.getCurrentPosition(onSuccess, onError);%0A  %09%7D
 %0A%09%0A 

Revert "Revert "Current location""