Android direction in Google Maps with latitude and longitude - android

I want send my origin point and destination point to Google for direction.
When I use name for origin and destination it's true and returns true JSON information, but when I send latitude and longitude for origin and destination it doesn't work.
It's ok whit this URL:
https://maps.googleapis.com/maps/api/directions/json?origin=tehran&destination=shiraz&key=AIzaSyBvR07aFM-1ddGVgt392lRnUge3weT6nUY
But it doesn't work with this:
https://maps.googleapis.com/maps/api/directions/json?origin=32,52&destination=34,54&key=AIzaSyBvR07aFM-1ddGVgt392lRnUge3weT6nUY

I think the problem is the coordinates you're using - they look like they're not accessible via roads. Make sure that you're not casting the latitude or longitude to ints, you need the decimal-point precision.
Converting Tehran and Shiraz to latlngs, I get the following URL which works correctly:
https://maps.googleapis.com/maps/api/directions/json?origin=35.6887931,51.3891646&destination=29.5916593,52.583701&key=<api key here>

Related

get google maps data with retrofit 2

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.

Calculation for latitude and longitude from start to destination point

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

How to calculate distance between two areas in a city

I wanted to make an android app which provides the distance between two areas in a city.
The user will have two input fields where he must enter the two area names he would like to find the distance.
After he enters the area name. My app should display the distance.
How should I implement this?
First of all you need to find latitude and longitude of that area name.
Convert both address in Location object, refer this.
Calculate distance by using distanceTo()
location1.distanceTo(location2);
Returns the approximate distance in meters between this location and
the given location.
refer this for distanceTo() detail.
First get latitude and longitude of your start point and end point and using
distanceBetween method of Location class calculate the distance here is link
http://developer.android.com/reference/android/location/Location.html#distanceBetween(double,%20double,%20double,%20double,%20float[])
Use the Google Maps Directions API. You'll need to request the directions over HTTP. You can do this directly from Android, or via your own server.
For example, directions from Montreal to Toronto:
GET http://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&sensor=false
You'll end up with some JSON. In routes[].legs[].distance, you'll get an object like this:
"legs" : [
{
"distance" : {
"text" : "542 km",
"value" : 542389
},
You can also get the polyline information directly from the response object.
for more detail visit here. Get the distance between two locations in android?

GeoJSON coordinates

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.

How to calculate the distance between the two given latitude and longitude while Location onchanged method is called

I have some queries regarding the using the google route map , currently iam working in Android , and the application iam developing uses
google map , actually the apps i for Car hiring , suppose the client send the pickup add and destination add , now the dirver will get the request that ther
is a pickup request , now supose currently driver is in some other location (A), and his pickup request is from location (B),, no i have to calculate the distance between driver location (A) and the pickup location (B) , I tried using the method given in Android Location ,but iam not getting the correct
distance
I have use the method
float[] result=new float[5];
myLocation.distanceBetween(ServerData.LATITUDE,ServerData.LONGITUDE, latitude,longitude,result);
String distance=Float.toString(result[0]);
here
ServerData.LATITUDE----> when the driver login sends it current location
ServerData.LONGITUDE
latitude--- > is the location moving towards the pickup point
longitude
can any one suggest how to do I am stuck with it
As that function takes a double you should better use double maybe adding a line somewhere you get your coordinates from
lat = Double.parseDouble(coordinates[0]);
long = Double.parseDouble(coordinates[0]);
And as above mentioned check for result[1] as well.

Categories

Resources