【问题标题】:How to draw polyline similar to google map app in android?如何在android中绘制类似于谷歌地图应用程序的折线?
【发布时间】:2016-06-08 05:52:43
【问题描述】:

我们将在地图上绘制的折线与谷歌地图应用程序的折线不相似。它给人一种很好的3d感觉,我们可以绘制类似于该折线的折线吗?是否可以使用9-绘制修补图像?。有人请帮忙吗?

【问题讨论】:

  • 不,这是不可能的。确实 GoogleMaps 并没有像我们一样使用 play services api,但他们有更多的方法可以使用。

标签: android google-maps google-polyline


【解决方案1】:

你好,这对你有帮助,对我有帮助。

首先从谷歌开发者账户中创建谷歌api服务器密钥,然后添加谷歌方向的依赖项。

compile 'com.akexorcist:googledirectionlibrary:1.0.4'

然后它检查 LatLongs 之间的可行和最短路线。

使用此代码检查路线是否可用。

GoogleDirection.withServerKey(getResources().getString(R.string.SERVER_KEY))
                    .from(SourceLatlng)
                    .to(DestinationLatlng)
                    .execute(new DirectionCallback() {
                        @Override
                        public void onDirectionSuccess(Direction direction, String message) {
                            if (direction.isOK()) {
                                DrawRoute(direction, message,SourceLatlng,DestinationLatlng);
                            } else {
                                //selectedRawLine = ERROR;
                            }

                        }

                        @Override
                        public void onDirectionFailure(Throwable t) {
                            t.printStackTrace();
                        }
                    });

使用这个我们可以发现路由是否可行

private void DrawRoute(Direction direction, String message,LatLng sourceLatlng,LatLng DestinationLng) {

        for (Route route : direction.getRouteList()) {
            PolylineOptions polyoptions = new PolylineOptions();
            polyoptions.color(getResources().getColor(R.color.blackcolor));
            polyoptions.width(5);
            polyoptions.addAll(route.getOverviewPolyline().getPointList());
            poly = googleMap.addPolyline(polyoptions);
            poly.setClickable(true);

        }
        LatLngBounds.Builder latLngBuilder = new LatLngBounds.Builder();
        if(sourceLatlng!=null)
        latLngBuilder.include(sourceLatlng);
        if(DestinationLng!=null)
        latLngBuilder.include(DestinationLng);

        try {
            LatLngBounds bounds = latLngBuilder.build();
            CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds,
                    UiHelper.dpToPixel(getActivity(), 135));
            googleMap.animateCamera(cu);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

使用这段代码,我们在两个 latLongs 之间创建折线 ...

【讨论】:

  • 我试过折线,但谷歌地图的(系统应用)折线与这条折线不同
  • 你可以改变折线的颜色和地图折线一样,用这个改变折线的宽度。
  • polyoptions.width(5);
  • 5 到 10。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-16
  • 1970-01-01
  • 2018-03-06
  • 2016-05-14
  • 2014-03-19
  • 1970-01-01
相关资源
最近更新 更多