首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在两个拉特龙点之间划线?

如何在两个拉特龙点之间划线?
EN

Stack Overflow用户
提问于 2017-04-27 08:13:17
回答 3查看 4.1K关注 0票数 1

使用Polyline,我可以在两点之间创建一条路径。

,但当我使用这两点(艾哈迈达巴德到纽约),polyline不是创建。否则,如果两点之间没有海,它就会工作。

,当点像时,我会遇到问题

,但在这种情况下,它从布吉到艾哈迈达巴德的工作

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-04-29 06:28:51

最后,我得到了答案:OlaUber应用程序是如何做这些的。

代码语言:javascript
复制
ArrayList<LatLng> points = new ArrayList<LatLng>();
                PolylineOptions polyLineOptions = new PolylineOptions();
                points.add(new LatLng(from_latitude,from_longitude));
                points.add(new LatLng(to_latitude,to_longitude));
                polyLineOptions.width(7 * 1);
                polyLineOptions.geodesic(true);
                polyLineOptions.color(activity.getResources().getColor(R.color.black));
                polyLineOptions.addAll(points);
                Polyline polyline = mMap.addPolyline(polyLineOptions);
                polyline.setGeodesic(true);
票数 4
EN

Stack Overflow用户

发布于 2017-04-27 08:19:22

你可以像在下面画一样

代码语言:javascript
复制
 PolylineOptions rectOptions = new PolylineOptions();
    LatLng polLatLng = null;
    if (points.size() > 0) {
        ArrayList<LatLng> pathPoint = new ArrayList<LatLng>();
        for (int k = 0; k < points.size(); k++) {
            double polLat = points.get(k).latitude;
            double polLng = points.get(k).longitude;
            pathPoint.add(new LatLng(polLat, polLng));
            polLatLng = new LatLng(polLat, polLng);
        }
        double startLatitude = points.get(0).latitude;
        double startLongitude = points.get(0).longitude;
        double endLatitude = points.get(points.size() - 1).latitude;
        double endLongitude = points.get(points.size() - 1).longitude;
        LatLng start = new LatLng(startLatitude, startLongitude);
        LatLng end = new LatLng(endLatitude, endLongitude);

        mMap.addMarker(new MarkerOptions().position(start).title("start"));
        mMap.addMarker(new MarkerOptions().position(end).title("end"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(polLatLng));
        mMap.animateCamera(CameraUpdateFactory.zoomTo(10));
        rectOptions.addAll(pathPoint);
        rectOptions.width(10);
        rectOptions.color(Color.BLUE);
        mMap.addPolyline(rectOptions);
票数 0
EN

Stack Overflow用户

发布于 2017-04-27 08:20:11

代码语言:javascript
复制
 solution 1:

    private void showDirection(LatLng source, LatLng destination) {

    Map<String, String> hashMap = new HashMap<String, String>();

    final String url = "http://maps.googleapis.com/maps/api/directions/json?origin="
            + source.latitude
            + ","
            + source.longitude
            + "&destination="
            + destination.latitude
            + ","
            + destination.longitude
            + "&sensor=false";
    new HttpRequester(activity, hashMap, StaticValues.ServiceCode.GET_ROUTE, true,
            this);
    Utils.showCustomProgressDialog(activity,
            getString(R.string.text_getting_direction), false, null);
}


solution 2:
private void build_retrofit_and_get_response(String type) {

    String url = "https://maps.googleapis.com/maps/";

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(url)
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    RetrofitMaps service = retrofit.create(RetrofitMaps.class);

    Call<Example> call = service.getDistanceDuration("metric", StartLocation.latitude + "," + StartLocation.longitude,
            EndLocation.latitude + "," + EndLocation.longitude, type);

    call.enqueue(new Callback<Example>() {
        @Override
        public void onResponse(Response<Example> response, Retrofit retrofit) {

            try {
                //Remove previous line from map
                if (line != null) {
                    line.remove();
                }
                // This loop will go through all the results and add marker 
on each location.
                for (int i = 0; i < response.body().getRoutes().size(); i++) {
                    String distance = response.body().getRoutes().get(i).getLegs().get(i).getDistance().getText();
                    String time = response.body().getRoutes().get(i).getLegs().get(i).getDuration().getText();
//          activity.setTitleActionBar("Distance:" + distance + ", Duration:" + time);
                    String encodedString = response.body().getRoutes().get(0).getOverviewPolyline().getPoints();
                    List<LatLng> list = decodePoly(encodedString);
                    line = mGoogleMap.addPolyline(new PolylineOptions()
                            .addAll(list)
                            .width(10)
                            .color(Color.RED)
                            .geodesic(true)
                    );
                }
            } catch (Exception e) {
                Log.d("onResponse", "There is an error");
                e.printStackTrace();
            }
        }

        @Override
        public void onFailure(Throwable t) {
            Log.d("onFailure", t.toString());
        }
    });

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43652205

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档