How to track facebook current user's location IOS/Android - android

Is there any way I can track a facebook's user's location in real time who is logged in my mobile app and has location services enabled and also has granted access to my app so as to make use of its location?
Assuming a user X, and 3 linear points in space: A,B,C.
X is traveling from A to C.
Is there an SDK that would enable me to check X's real time location ( latitude + longitude ) at any given time while X is moving from A to C so as to create a dotted map(by dropping a pin on the map) with the user's location at every 10ms?
Is this feasible given the fact that my device has a 4G internet connection?

I think you can use CLLocationManager to update user location after traveling a number of meters. I presume you are already having a CLLocationManager to update your location? you can save the dots in an array (starting with the location of A, ending with location of C). You can then draw a line using the dots. I believe Google Map API has a method for drawing line. There's an answer for that here:
Here is a link from SO
But for the sake of providing code, I will provide it for you in Swift 3.0 (the code in the link is in ObjC):
override func viewDidLoad() {
super.viewDidLoad()
//This is a dummy location, you'd add locations to it using the
// func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
let location:CLLocation = CLLocation(latitude: 200, longitude: 100)
let locationArray:Array<CLLocation> = [location]
let camera:GMSCameraPosition = GMSCameraPosition.camera(withLatitude: (locationArray.first?.coordinate.latitude)!, longitude: (locationArray.first?.coordinate.longitude)!, zoom: 2)
//You can obtain the Lat and Long for above from the list of arrays of locations you saved
//You can use the .first or .last on the array (I used first)
let mapview:GMSMapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
let path:GMSMutablePath = GMSMutablePath()
for nextLocation in locationArray {
if locationArray.index(of: nextLocation) != 0 {
//You dont want to use the first one as you've already done it
//so you start with 1
path.addLatitude(nextLocation.coordinate.latitude, longitude: nextLocation.coordinate.longitude)
}
}
let polyline:GMSPolyline = GMSPolyline(path: path)
polyline.strokeColor = UIColor.red
polyline.strokeWidth = 2
polyline.map = mapview
self.view = mapview
//I personally prefer view.addSubview(mapview)
}

Related

Android path follow (Google map) Programmatically

is it possible to follow a path on google map android (Programmatically) if my android device getting away from the path it notify or show alert that your not following your path
Help will be appriciated,
Thank's :)
Yes, it's possible by several ways. For example you can use PolyUtil.isLocationOnPath(LatLng point, java.util.List<LatLng> polyline, boolean geodesic, double tolerance) from Google Maps Android API Utility Library. In this case you need to check (with isLocationOnPath()) if user location laying on segment of the polyline of your path. Something like that:
if (!PolyUtil.isLocationOnPath(userLocationPoint, pathPolyline.getPoints(), true, 50)) {
// user away of pathPolyline more than 50 meters
// show your alert here
...
}
}
where 50 - is tolerance (in meters).
NB! It's not a complete solution - just approach.
Also you can use geofence monitoring for several waypoints (with a limit of 100 per device user).

Changing destination coordinates at runtime (Dynamically)

I want to program an Android application where user A can navigate it self to user B (using Google Maps and their Navigator).
But I want my android application to update the coordinates of user B and send it to user A in real time.
My question is: Are there any way for user A to retrieve the updated coordinates AND not getting a new route calculated every time that user B change its position?
Since I want my user B to send new coordinates every 15 meters, it would be hell if user A gets a new route calculated every time.
You can use setDirection() method on the renderer and pass it to DirectionsResult. The DirectionsResult contains the result of the directions query, which you may either handle yourself which can automatically handle displaying the result on a map. The renderer is an MVCObject, it will automatically detect any changes to its properties and update the map when its associated directions have changed.
The following example calculates directions between two locations on Route, where the origin and destination are set by the given "start" and "end" values in the dropdown lists. The DirectionsRenderer handles display of the polyline between the indicated locations, and the placement of markers at the origin, destination and any waypoints, if applicable.
function calcRoute() {
var start = document.getElementById('start').value;
var end = document.getElementById('end').value;
var request = {
origin: start,
destination: end,
travelMode: 'DRIVING'
};
directionsService.route(request, function(result, status) {
if (status == 'OK') {
directionsDisplay.setDirections(result);
}
});

Google Map V2 Android and iOS place latlng decimal places

There is an Android as well as iOS application that I am working on.
Both the applications use google's PlaceAutocomplete controller to get a location's lat-long. In iOS we get lat-long upto 6 decimal places sometimes 5 also. Where as in android we get more than 6 decimal places. The precision of the same location coordinate for Android and iOS differs.
For example consider location Pune
Android Latlng: 18.520431,73.856744
iOS Latlng: 18.52043,73.856744
So as you can see there is difference between the precision of latitudes of the same location.
Is there a way to avoid this as my application needs comparison of these lat-longs?
You should not rely on the precision of the coordinates to compare them because they can change or, as you experiment, vary between platforms.
Instead, you can set a tolerance to determine if two locations are the same. For example:
float YOUR_TOLERANCE = 1; // 1 meter
if (location.distanceTo(otherLocation) < YOUR_TOLERANCE) {
// Both locations are considered the same
}
In android also there is three type of location :
GPS_PROVIDER
NETWORK_PROVIDER
PASSIVE_PROVIDER
So, as per my coding experience i come to know that if you use :
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 10, new MyLocationListener());
you will get long precision of decimal like more then 14+ and if you will you use fusion of them with this :
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, my_google_listener);
then you will get 6 to 7 digit of precision. try it !!!

Google Maps API for Android - detecting buildings/obstacles between me and location

Hypothetical question. I'm building an augmented reality app using Google Maps API for Android. I'm wondering if there's any data that I can use to determine whether a building lies between me and a specified location. I ask this because when sufficiently zoomed-in, there is clearly 3D data on the shape of buildings included on the map. I was wondering if there was a method like:
boolean buildingInTheWay(myLocation, destinationLocation);
if (buildingInTheWay) {
//Do something
} else {
//Do something else
}
Perhaps there's also something that could be done where if the route to a location is much longer than the birds-eye path to a location, there must be an obstacle in the way (imagine two parallel streets like so:
- = street
X = buildings
A = start location
B = destination location
---------C----A-------
xxxxxxxx | xxxxxxxxx
---------D----B-------
Here, A to B would return true, as the route around the buildings is a lot longer than the direct distance. But C to D would return false, as the route following a road is almost exactly the same distance.
However, that's not very accurate - what about between buildings? I wonder if each building on Google Maps has lat/lng points for each of its corners?
Any thoughts, anyone?

Using Phonegap to store traveled distance

I am writing an application using phonegap to store an update lat/lon every 5 seconds to a mysql database. I would like to be able to allow my users to see the total distance traveled since starting the app.
I've taken a look at the Phonegap geolocation API and cannot see a way to calculate total distance traveled based upon lat / lon updates. Is there a way to accomplish this?
EDIT: # Drew thanks for the link. I have looked it over and the JS version of Haversine looks straight forward. the difficult part will be the way phonegap pulls and stores lat/lon. Currently my function to get and send the location to MySQL is
function geo_success(position) {
$("#status p").text("Tracking active");
$('#status').removeClass("stopped").addClass("active");
$('button').text("Stop tracking");
latlon.lat = position.coords.latitude;
latlon.lon = position.coords.longitude;
latlon.alt = position.coords.altitude;
if(!position.coords.speed) { latlon.speed = 0; }
else{ latlon.speed = position.coords.speed }
if(first) {
intervalId = setInterval(send, 5000);
}
first = false;
}
Is there a way you can think of to store the latest value for lat1 lon1 and use the previous for lat2 lon2 and cycle the newest incoming coordinates through those 2 sets of variables? That way i can take the returned variable d from the haversine and store it in the db (to be able to sum it up later). Many thanks.
You would have to create an algorithm yourself that take those coordinates every 5 seconds, do some algebra on them to determine the distance between the two, and add it to the total distance somewhere, then repeat for the next 5 seconds.
For the actual algorithm of calculating the distance, look at this answer.

Categories

Resources