如何在 android 中的 google 地图上绘制折线
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);
}
});
}
这是我的代码 我想在 google 地图上绘制层线 我可以同时移动标记 我想绘制移动线的路径 google 地图。
public void RealTimeLocation(int memberId, final double lat, final double lng) {
a
使用这种方法,我在位置更改时得到 4 到 5 个纬度 我正在尝试添加 freindlatlong.add(point1);
其中 freindlatlong 是数组列表,根据我尝试添加 Plyline 但不起作用请建议我如何在地图上绘制路径线。
试试这个,非常好的绘制折线的代码:
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);
@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);
}
});
}
};
请替换此代码
@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);
}
});
}
这是我的代码 我想在 google 地图上绘制层线 我可以同时移动标记 我想绘制移动线的路径 google 地图。
public void RealTimeLocation(int memberId, final double lat, final double lng) {
a
使用这种方法,我在位置更改时得到 4 到 5 个纬度 我正在尝试添加 freindlatlong.add(point1);
其中 freindlatlong 是数组列表,根据我尝试添加 Plyline 但不起作用请建议我如何在地图上绘制路径线。
试试这个,非常好的绘制折线的代码:
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);
@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);
}
});
}
};
请替换此代码