'how to draw poly line on google map in android
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.act_chat);
}
@Override
onResume() {
if (map != null) {
// Enable MyLocation Button in the Map
map.setMyLocationEnabled(true);
map.getUiSettings().setZoomControlsEnabled(false);
try {
LatLng point = new LatLng(Double.parseDouble(Latreccvier),
Double.parseDouble(Lonreccvier));
BitmapDescriptor icon = BitmapDescriptorFactory
.fromResource(R.drawable.reccivermarker);
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(point);
markerOptions.icon(icon);
map.addMarker(markerOptions);
// // Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(point, 14));
map.animateCamera(CameraUpdateFactory.zoomTo(14), 2000, null);
} catch (Exception e) {
}
}
}
@Override
public void RealTimeLocation(int memberId, final double lat, final double lng) {
// TODO Auto-generated method stub
runOnUiThread(new Runnable() {
public void run() {
Latreccvier = String.valueOf(lat);
Lonreccvier = String.valueOf(lng);
LatLng point1=new LatLng(Double.parseDouble(Latreccvier), Double.parseDouble(Lonreccvier));
friendMarker.setPosition(point1);
}
});
}
this is my code i want to draw ply line on google map i am able to move marker at same time i want to draw path of line of moving google map.
public void RealTimeLocation(int memberId, final double lat, final double lng) {
a
using this method i am getting 4 to 5 lat long on Location changed i am trying to add freindlatlong.add(point1);
where freindlatlong is array list according to that i try to add Plyline but not work please suggest me how to draw path line on map.
Solution 1:[1]
@Override
onResume() {
if (map != null) {
// Enable MyLocation Button in the Map
map.setMyLocationEnabled(true);
map.getUiSettings().setZoomControlsEnabled(false);
try {
LatLng point = new LatLng(Double.parseDouble(Latreccvier),
Double.parseDouble(Lonreccvier));
BitmapDescriptor icon = BitmapDescriptorFactory
.fromResource(R.drawable.reccivermarker);
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(point);
markerOptions.icon(icon);
map.addMarker(markerOptions);
// map.addPolyline(options);
// // Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(point, 14));
map.animateCamera(CameraUpdateFactory.zoomTo(14), 2000, null);
} catch (Exception e) {
}
}
}
@Override
public void RealTimeLocation(int memberId, final double lat,
final double lng) {
// TODO Auto-generated method stub
runOnUiThread(new Runnable() {
public void run() {
Latreccvier = String.valueOf(lat);
Lonreccvier = String.valueOf(lng);
LatLng point1 = new LatLng(Double.parseDouble(Latreccvier),
Double.parseDouble(Lonreccvier));
cordinatelist.add(point1);
friendMarker.setPosition(point1);
// options.add(point1);
}
});
}
};
please replace this code
Solution 2:[2]
Try this ,very good code for drawing poly-line:
MarkerOptions markerOptions = new MarkerOptions();
// Setting latitude and longitude of the marker position
markerOptions.position(point);
// Setting titile of the infowindow of the marker
markerOptions.title("Position");
// Setting the content of the infowindow of the marker
markerOptions.snippet("Latitude:"+point.latitude+","+"Longitude:"+point.longitude);
// Instantiating the class PolylineOptions to plot polyline in the map
PolylineOptions polylineOptions = new PolylineOptions();
// Setting the color of the polyline
polylineOptions.color(Color.RED);
// Setting the width of the polyline
polylineOptions.width(3);
// Adding the taped point to the ArrayList
points.add(point);
// Setting points of polyline
polylineOptions.addAll(points);
// Adding the polyline to the map
googleMap.addPolyline(polylineOptions);
// Adding the marker to the map
googleMap.addMarker(markerOptions);
Reference : Adding poly-line on tap
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Departure |
Solution 2 | userAndroid |