我想在谷歌地图上画路径。
基本上,我正在跟踪用户位置,在特定时间间隔后。 当用户到达某个目的地时,我需要绘制他到达目的地所经过的路径。
这个功能工作得很好,但问题是它显示了错乱的路径。 请参见下面的图像。
我想要什么:
我想要绘制出沿途经过的正确路径。
我尝试过的方法
我搜索并找到了这个链接,我们可以通过该链接传递最多8个点来获取方向。 这是非商业用户使用谷歌地图的最大限制。 是否有其他方法可以实现这一点。 因为我有很多要在地图上绘制的点。
用于绘制折线的代码
private void drawPath() {
if (mMap != null)
mMap.clear();
int count = 0;
LatLng prev = null;
String[] mProjection = {LocTable.COLUMN_ID, LocTable.COLUMN_LONGITUDE, LocTable.COLUMN_LATITUDE};
String mSelectionClause = LocTable.COLUMN_ID + "> ?";
String[] mSelectionArgs = {"0"};
String mSortOrder = LocTable.COLUMN_ID;
Cursor mCursor = getContentResolver().query(
LocContentProvider.CONTENT_URI, // The content URI of the words table
mProjection, // The columns to return for each row
mSelectionClause, // Selection criteria
mSelectionArgs, // Selection criteria
mSortOrder);
if(mCursor != null && mCursor.getCount()!=0) {
Log.i("cursor", "Count: " + mCursor.getCount() + "|Column count: " + mCursor.getColumnCount());
if (mCursor.moveToFirst()) {
do {
if (mMap != null) {
float lon = mCursor.getFloat(1);
float lat = mCursor.getFloat(2);
LatLng current = new LatLng(lat, lon);
markerPoints.add(current);
if (count == 0){
prev = current;
}
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(current, 19);
mMap.animateCamera(cameraUpdate);
mMap.addPolyline((new PolylineOptions())
.add(prev, current).width(6).color(Color.BLUE)
.visible(true));
prev=current;
count++;
}
} while (mCursor.moveToNext());
}
mCursor.close();
}
}
感谢您的帮助。