This is how i get current position:

```
navigator.geolocation.getCurrentPosition(function(pos) {
latlong = { 'lat' : pos.coords.latitude, 'long' : pos.coords.longitude }
$rootScope.$broadcast('currentLocation', { currentLocation: latlong });
$rootScope.currentLocation = latlong;
}, function(error) {
console.log('Got error!');
console.log(error);
latLong = null
q.reject('Failed to Get Lat Long')
});
```

And then i use this to calculate the distance:

```
//currentlocation
var from = new google.maps.LatLng($rootScope.currentLocation.lat, $rootScope.currentLocation.long);
//value[1] contains latitude value[2] contains longitude
var to = new google.maps.LatLng(value[1],value[2]);
//calculate distance using google maps
var dist = google.maps.geometry.spherical.computeDistanceBetween(from, to);
//distance is returned p meter
var km = dist / 1000;
//if its 1000 meters say km and round to whole else return distance tofixedwhich(0) is pretty much the same as math.round
if(km > 1){
var dist =(Math.round(km) + " km");
}else {
var dist =(dist.toFixed(0) + "m");
}// 1613.8 km
```