android - 如何在 Android Google Maps API 上平滑折线方向?

标签 android google-maps

我在 Android Google Maps API 上有两个位置的折线用于指示方向,但是,您可以看出拐角是锯齿状的且不平滑。是否需要采取任何措施来平滑这些线条以显得更自然(就像在谷歌自己的 map 网站上一样)

下面是使用适当的参数调用来创建折线的类

public class GetDirectionsData extends AsyncTask<Object, String, String> {

String googlePlacesData;
GoogleMap mMap;
String url;
LatLng latlng;


@Override
protected String doInBackground(Object... objects) {
    mMap = (GoogleMap)objects[0];
    url = (String)objects[1];
    latlng = (LatLng)objects[2];

    DownloadUrl downloadUrl = new DownloadUrl();
    try {
        googlePlacesData = downloadUrl.readUrl(url);
    } catch (IOException e) {
        e.printStackTrace();
    }

    return googlePlacesData;
}

@Override
protected void onPostExecute(String s){
    String[] directionsList;

    DataParser parser = new DataParser();
    directionsList = parser.parseDirections(s);
    displayDirections(directionsList);
}

public void displayDirections(String[] directionsList){
    int count = directionsList.length;
    for(int i = 0; i<count; i++){
        PolylineOptions options = new PolylineOptions();
        options.color(Color.rgb(0,179,253));
        options.width(15);
        options.addAll(PolyUtil.decode(directionsList[i]));
        mMap.addPolyline(options);
    }
}

enter image description here

最佳答案

将所有方向添加为一条折线,而不是将单独的折线添加为单独的方向:使用类似的内容

public void displayDirections(String[] directionsList){
    PolylineOptions options = new PolylineOptions();
    options.color(Color.rgb(0,179,253));
    options.width(15);
    int count = directionsList.length;
    for(int i = 0; i<count; i++){
        options.addAll(PolyUtil.decode(directionsList[i]));
    }
    mMap.addPolyline(options);
}

而不是

public void displayDirections(String[] directionsList){
    int count = directionsList.length;
    for(int i = 0; i<count; i++){
        PolylineOptions options = new PolylineOptions();
        options.color(Color.rgb(0,179,253));
        options.width(15);
        options.addAll(PolyUtil.decode(directionsList[i]));
        mMap.addPolyline(options);
    }
}

因为JointType影响折线的点,而不是单独的折线。

关于android - 如何在 Android Google Maps API 上平滑折线方向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49662847/

相关文章:

java - 滑动菜单和 Maven

java - 在两个 Android 应用程序之间共享数据/标志

android - 为什么我无法从包名称启动应用程序

android - 在android中的sqlite中使用更新语句

android - 如何以米为单位测量 Google map 的相机视口(viewport)?

java - Android 的 getBSSID() 方法错误?

javascript - 如何通过单击谷歌地图内的按钮来调用 Vue js 的方法

ios - 通过Google API知道所选位置是否是机场

使用自定义标记在多个叠加层上绘制 Android 谷歌地图文本

javascript - 更新 AngularJS 服务中的 $scope 对象不会更新 View