Hi I am new to android development.
I am on college project its based on location which is need to find list of latitude and longitude in between two points.
Given Starting position is 12.990143,80.215784 and destination position is 12.992595,80.217618.
Over the past days i search the google, i found so many links to find distance between locations and mid point. I cant able to find solution for my problem.
Please suggest some solution for this problem. I am struggling over days to find solution for this.
Thanks in advance
You can use the SphericalUtil.interpolate method from the Google Maps API Utility Library.
For example you can find a LatLng that is at 1/5 of the distance between your starting position and your destination by doing
LatLng origin = new LatLng(12.990143,80.215784);
LatLng destination = new LatLng(12.992595,80.217618);
LatLng result = SphericalUtil.interpolate(origin, destination, 0.2);
You can use the google Directions api to obtain a full PolyLine of the path. You can objain a JSON object and parse it to obtain locations in the path.
http://maps.googleapis.com/maps/api/directions/json?origin=12.990143,80.215784&destination=12.992595,80.217618&mode=driving
This will return a full JSON result which contains everything you would need to find the whole route to all the points falling on it.
You can look more into it on:
https://developers.google.com/maps/documentation/directions/intro#Introduction
Related
I try to get the distance between two points by showing them together with a polyline. One marker is permanently somewhere and the other the user chooses the place they want when clicking on the map. I tried with many codes obtained from the Internet but for me neither works or just gives me the marker of a place with the latutude and longitude. I want to use retrofit 2 to bring the information. Can anyone help me with that?
On clicking on map you are placing marker, So if you want to get location of that marker then simply you can got that marker position using that marker object like this.
Double latitude = marker.getPosition().latitude;
Double longitude = marker.getPosition.longitude;
and you have already one location so you can find distance between two locations using this.
locationFrom.distanceTo(locationDestination);
here locationFrom is your source location from where you want to find distance and locationDestination is your destination location to where you find distance.
I need help to put markers on Android Map. I am receiving a JSON string from a WebService that use GeoJSON.
I could parse it, but the coordinate system is not the traditional, and I don't know how to put the markers on map.
This is the example that I am using:
double latitude = 5441638.1188548915 // this value came from WS
double longitude = 6352789.023657421 // this value came from WS
map.addMarker(new MarkerOptions()
.title(jsonObj.getString("Restaurants"))
.position(new LatLng(
latitude,
longitude
))
);
What i want to know if is there is any method to convert the coordinates to the classic system (ex: -30.5645, -50.2328) , or an Android method to work with the other system of coordinates.
I hope you can help me,
Thanks!
I've put this as an answer, but regrettably it's not a complete one.
Your position is likely not to be lat/lon but Eastings and Northings.
The conversion process is quite complex. In actuality your WebService should be stating which Coordinate Reference System (crs) it is using as the GeoJSON default is WGS84
You should see if you can get the WebService to supply "proper" coordinates instead.
I am unable to get proper absolute distance from source to destination on google map.
return location.distanceTo(dest latitude and longitude);
and also i used
distanceBetween()
distance2 = distanceBetween((Location) newMarkerList.get(0));
but I am not getting the correct result; any and all help is appreciated.
There is a method for that in Location class - check here
If that's not working it means you are either expecting incorrect values or are not passing the right ones.
I am trying to share google map with my current location in my app(similar to whatsapp), I searched for it but didn't find any solution. Can anybody guide me that how can I start working over it. I don't have any idea that how should I start this.
We need to know how you plan to share this data, but in general you can share your GeoPoint variable that contains your latitude and longitude position on the globe..
GeoPoint(int latitudeE6, int longitudeE6)
// Constructs a GeoPoint with the given latitude and longitude, measured in microdegrees (degrees * 1E6).
How to find distance from polyline in google map in android using map apiV2 ? I want to find distance when user start moving from one location to another .
I used the Calculate distance in meters when you know longitude and latitude in java but it takes distance between two lat-long not as per user
moves in map. Please help me if anyone knows how to find distance using polyline.
For finding distance from your polyline you can use PolyUtil class which contains one method distanceToLine .
implementation'com.google.maps.android:android-maps-utils:0.5+'
add this library in your build.gradle.
For more you can use Google map utility class
https://developers.google.com/maps/documentation/android-api/utility/
For this you need to use thread. In that at regular interval you should find the distance between current coordinates and last saved coordinate.
Raw code:
Coordinate current, last;
Distance D = 0;
while (true) {
wait(10000);
last = current;
current = getNewCordinate;
d = D + distFrom(current, last);
}
This logic will help.
Based on the answer given by Gevaria Purva I found a more appropriate method on PolyUtil named isLocationOnPath.
For the third parameter most likely you want to pass true.