GeoJSON coordinates - android

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.

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.

Android direction in Google Maps with latitude and longitude

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>

Compare Marker.getPosition() and LatLang

My app gets updated GPS coordinates periodically which I show using a Marker on map. I need to move the marker to a new position if the new GPS coordinates are different then what Marker is currently showing.
The problem is that comparing Marker.getPosition() is more accurate while LatLang is not, hence sometimes even when they are the same, my logic says they are different.
How to solve this issue?
Please note that the same LatLang i assign to Marker.
You can consider that two LatLngs are virtually the same if the distance between them is less than a given tolerance.
You can use the SphericalUtil.computeDistanceBetween method from the Google Maps Android API Utility Library
float YOUR_TOLERANCE = 1; // 1 meter
if (SphericalUtil.computeDistanceBetween(pos, buslatLng) < YOUR_TOLERANCE) {
// Both locations are considered the same
}

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 find distance from polyline in android?

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.

Categories

Resources