Friday, 14 September 2018

Get distance and draw line between two location android google maps

I have a app that opens the map and zooms on my location with a marker and then if i longClick on any place it saves that location in database everything works fine but one thing i cannot manage is draw a line of path between two location markers.

these are three global variables

 Location myLocation;
 LatLng onmaplongclicklastlatlng;
 private GoogleMap mMap;

mylocation is assigned by LocationListener and onmaplongclicklastlatlng is assigned when i long click on any place on the map.

placing the marker on both location is done i already have the two points i want to draw the line on.

i just need to draw a line between those two locations (my current location periodically updated in the myLocation variable)

and onmaplongclicklastlatlng changed whenever i long click on the map.

the whole code is done and i have a button that i want to use to draw the line since i can access the two location variables from this button method, Other code need not be changed.

public void getLine(View view) {

    // need to draw a line here from user gps posiution to the marker location    
}

i have tried many tutorials but they do not work for some reason, any help would be really appreciated.

oh and last but not least

onmaplongclicklastlatlng

is a LatLng and

myLocation

is a Location

but they can be interchanged to fit the purpose

ex. Location maplocation = new Location(onmaplongclicklastlatlng
.latitude, onmaplongclicklastlatlng.longitude);

and

Latlng myLatLng = new LatLng(myLocation.getLatitude(), myLocation.getLongitude());

As i said any help would be really appreciated. And let me know if anything else needed i will edit the question then.



from Get distance and draw line between two location android google maps

No comments:

Post a Comment