get google maps data with retrofit 2 - android

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.

Related

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

Getting Google Maps Intent to Return Location

So I am trying to build an app that would allows the user to select a particular place from a Google Maps intent, and when the user pick a place, the intent would finish and return the latitude and longitude data to the previous activity.
What is the best way to do this?
What I have done so far:
I used GPSTracker from here.
to get the current latitude and longitude, and then used these data to start a google map intent pointing to current location.
The website you posted in your question does not look like it contains the actual map. If you need assistance with adding a Google Map to your application I would start here.
Assuming you have that working and your code allows a user to place his or her point already, you can retrieve the coordinates of that point by using a built in function in the Marker class getPosition().
You can use the coordinates by accessing the public variables .latitude and .longitude as follows:
LatLng coord = myMarker.getPosition();
double latitude = coord.latitude;
double longitude = coord.longitude;

How to mark evey next 100 meter travelled in map in android?

I am trying to get the GPS location co-ordinates(lat and lon vals) for every 100metrs.
For example, I am at particular location A and tried to fetch my current location using
location listener and shown in the map with marker, after that I have travelled 100metres and reached location B and again i tried to fetch location and shown in map with marker.
Good thing :-
i am getting but obvious new lat and lon cordinates for every next 100 meters.
Annoying Thing:-
Marker for location A and for location B getting overlapped always, so one cannot make out any sort of difference in between those two locations by dirrectly looking into map :(. How can I overcome this issue. Can you please guide me.?

Dispalying route travelled using latitude and longitude values in map

I have an android app which will continuously send location information to server (latitude and longitude values). Another application will retrieve these info and display it in textview.
What I need to do is in my second app which displays in text view I need to add a mapview which displays the location tarvelled by marking it on map using the latitude and longitude values.
How to do it ? Thanks in advance !
As you have fetched the location information, now you just need to mark points on the map view to show the desired location on map view, You should follow using google maps android
Here you will find a good example on how to add markers on mapview.

Categories

Resources