【发布时间】:2014-03-24 23:47:39
【问题描述】:
我在走路/开车时尝试绘制折线(逐点连接),但结果很乱(Image link)。我阅读了here 的建议并做了一些研究,我想出了以下代码来做到这一点:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment supportMapFragment = (SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.map);
googleMap = supportMapFragment.getMap();
googleMap.getUiSettings().setCompassEnabled(false);
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
googleMap.setMyLocationEnabled(true);
}
我先从initializeDraw()开始:
private void initializeDraw(){
rectLine = new PolylineOptions().width(5).color(Color.RED);
newPolyline = googleMap.addPolyline(rectLine);
}
然后我启动 OnLocationListener(使用 network_provider):
RTlocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, drawLocationOnMap);
locationListener(我从中更新点(lat/lng 并将凸轮聚焦在位置上):
LocationListener drawLocationOnMap = new LocationListener() {
public void onLocationChanged(Location location) {
LatLng newPoint = new LatLng(location.getLatitude(), location.getLongitude());
points = newPolyline.getPoints();
points.add(newPoint);
newPolyline.setPoints(points);
CameraPosition cameraPosition = new CameraPosition.Builder().target(new LatLng(location.getLatitude(), location.getLongitude()))
.zoom(18)
.bearing(0)
.tilt(70)
.build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
};
};
结果: Image link
通过查看上面的图像,即使我走了 100m 直线,它看起来也像“之字形”。对此的任何帮助将不胜感激。
【问题讨论】: