Google Map V2 Android and iOS place latlng decimal places - android

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 !!!

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).

How to track facebook current user's location IOS/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)
}

Able to fetch current location but its not accurate

This question may a repetition but i am not satisfied with others ,that is why asking again .i have created a simple app to show current location and displayed it on map.But its not accurate.I tested my app within a building and is fetching the nearby road as my current location,But other apps like Myteksi,Grab teksi is showing my company name as current location and its accurate.i dont know why its so.Please help.Code for fetching current location is giving below
protected void gotoCurrentLocation() {
Location currentLocation = mLocationClient.getLastLocation();
if (currentLocation == null) {
Log.d("currentLocation-->>>", "null");
Toast.makeText(this, "Current location isn't available",
Toast.LENGTH_SHORT).show();
} else {
LatLng ll = new LatLng(currentLocation.getLatitude(),
currentLocation.getLongitude());
Log.d("lattitude", currentLocation.getLatitude()+"");
Log.d("longitude", currentLocation.getLongitude()+"");
CameraUpdate update = CameraUpdateFactory.newLatLngZoom(ll,
DEFAULTZOOM);
map.animateCamera(update);
/*String address= service.GetAddress(currentLocation.getLatitude(),
currentLocation.getLongitude());
Log.d("address", address);*/
}
}
please comment if any other codes are needed.
As you said you test the app in indoor location. And you know in indoor locations GPS sensor will not work, According to google's docs:
Although GPS is most accurate, it only works outdoors.
So your location might come from Network Provider using wi-fi or cell-id, which is not enough accurate.
Android's Network Location Provider determines user location using cell tower and Wi-Fi signals, providing location information in a way that works indoors and outdoors.
and you must be aware of that:(when using getLastLocation() )
To get the current location, create a location client, connect it to Location Services, and then call its getLastLocation() method. The return value is the best, most recent location, based on the permissions your app requested and the currently-enabled location sensors.
BUT:
The current location is only maintained while a location client is connected to Location Service. Assuming that no other apps are connected to Location Services, if you disconnect the client and then sometime later call getLastLocation(), the result may be out of date.
and also please take a look at this to learn more about Maintaining a current best estimate:
http://developer.android.com/guide/topics/location/strategies.html#BestEstimate
I hope this information helps. ;)
This is because fetching location is a very complicated task to do. And the native implantation of LocationClient might not be the most accurate.
Consider using one or all the 13 sensors(Table 1) in your device to improve that.
TYPE_ACCELEROMETER Hardware Measures the acceleration force in m/s2 that is applied to a device on all three physical axes (x, y, and z), including the force of gravity. Motion detection (shake, tilt, etc.).
TYPE_AMBIENT_TEMPERATURE Hardware Measures the ambient room temperature in degrees Celsius (°C). See note below. Monitoring air temperatures.
TYPE_GRAVITY Software or Hardware Measures the force of gravity in m/s2 that is applied to a device on all three physical axes (x, y, z). Motion detection (shake, tilt, etc.).
TYPE_GYROSCOPE Hardware Measures a device's rate of rotation in rad/s around each of the three physical axes (x, y, and z). Rotation detection (spin, turn, etc.).
TYPE_LIGHT Hardware Measures the ambient light level (illumination) in lx. Controlling screen brightness.
TYPE_LINEAR_ACCELERATION Software or Hardware Measures the acceleration force in m/s2 that is applied to a device on all three physical axes (x, y, and z), excluding the force of gravity. Monitoring acceleration along a single axis.
TYPE_MAGNETIC_FIELD Hardware Measures the ambient geomagnetic field for all three physical axes (x, y, z) in μT. Creating a compass.
TYPE_ORIENTATION Software Measures degrees of rotation that a device makes around all three physical axes (x, y, z). As of API level 3 you can obtain the inclination matrix and rotation matrix for a device by using the gravity sensor and the geomagnetic field sensor in conjunction with the getRotationMatrix() method. Determining device position.
TYPE_PRESSURE Hardware Measures the ambient air pressure in hPa or mbar. Monitoring air pressure changes.
TYPE_PROXIMITY Hardware Measures the proximity of an object in cm relative to the view screen of a device. This sensor is typically used to determine whether a handset is being held up to a person's ear. Phone position during a call.
TYPE_RELATIVE_HUMIDITY Hardware Measures the relative ambient humidity in percent (%). Monitoring dewpoint, absolute, and relative humidity.
TYPE_ROTATION_VECTOR Software or Hardware Measures the orientation of a device by providing the three elements of the device's rotation vector. Motion detection and rotation detection.
TYPE_TEMPERATURE Hardware Measures the temperature of the device in degrees Celsius (°C). This sensor implementation varies across devices and this sensor was replaced with the
TYPE_AMBIENT_TEMPERATURE sensor in API Level 14 Monitoring temperatures
You might be getting stale location data, as you're using LocationClient.getLastKnownLocation(), which returns the last cached location, not the current one. You could try requesting your own location updates using a LocationListener. To do this, you need to create your own LocationListener and override the default onLocationChanged(Location) behavior. For example:
final LocationListener ll = new LocationListener(){
int i=0;
#Override
public void onLocationChanged(Location loc) {
if(i < 5 && loc.getAccuracy() > 8){
i ++;
return;
}
double lat = loc.getLatitude();
double lon = loc.getLongitude();
double acc = loc.getAccuracy();
}
};
You then need to register the listener using an instance of LocationManager:
final LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
This example will register the listener for whenever the GPS location changes. The actual listener code above waits for at least 5 location changes to help ensure that the final location is accurate (the longer time waited, the more time it will have had to lock-on to satellites), then gets the latitude, longitude, and accuracy from the Location object. There are many other ways that you can setup your listener, but that's the way that I did it in one of my apps. If you Google something like "android location updates", you should find some other good tutorials for it. Good luck!

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?

Android Google Maps | Get only directions route angle and distance

I'm need to use GoogleMaps for an android app
I need to build an android app that sends request to GoogleMaps API and recive only the list of directions (Turn right in 400meters at the next..) without showing any map
How to I update the list by user movement ?
(You currently passed first turn, heading to second turn.. 800 meters to next turn.. 400 meters to next turn)
If in answer 2 I get only String with "Left,Right,North.." How do I get the turn angle ?
(45-125 will be right, 90 will be absolute right)
I would like to hear about how to optimize the update ( There are 4 ways to use threads in android so I've heard )
Listen for Location Updates using requestLocationUpdates().
http://developer.android.com/training/location/receive-location-updates.html#StartUpdates

Categories

Resources