简体   繁体   English

如何在Android上使用Google Maps Directions API?

[英]How do I use Google Maps Directions API on Android?

I checked out the Google Maps API directions documentation but it just says a lot of things, can anyone show me a code on how to use the Directions API on Android? 我查看了Google Maps API说明文档,但它只是说了很多内容,有人可以向我展示如何在Android上使用Directions API的代码吗?

I just want Point A to have a line direction going to Point B. 我只想让A点的线方向转到B点。

Yes it is possible to intergrate direcitons api with map. 是的,可以将direcitons api与地图集成。 There is no need to write your own API. 无需编写自己的API。 You can achieve this very easily. 你可以很容易地实现这一目标。 With Google android api V2 there is no need to draw canvas. 使用Google android api V2,无需绘制画布。 Adding things in it is very easy. 添加内容非常简单。

Please read here for Google Maps https://developers.google.com/maps/documentation/android/start 请在此处阅读Google地图https://developers.google.com/maps/documentation/android/start

and for directions 和方向

https://developers.google.com/maps/documentation/directions/ https://developers.google.com/maps/documentation/directions/

During the process you have any specific problem then please ask that. 在此过程中您有任何具体问题,请询问。

Thanks, 谢谢,

Simple way If you know lattitude and longitude of your starting and ending point, then you can load google map with direction line in a webview. 简单方法如果您知道起点和终点的纬度和经度,则可以在webview中加载带有方向线的谷歌地图。

This is the code snippet for load google map in webview. 这是在webview中加载谷歌地图的代码段。

            WebView myWebView = (WebView) findViewById(R.id.webview);
            myWebView.setWebViewClient(new WebViewClient());
            myWebView.getSettings().setJavaScriptEnabled(true);

            final ProgressDialog progressDialog = new ProgressDialog(this);
            progressDialog.setMessage("Loading...");
            progressDialog.show();

            myWebView.setWebViewClient(new WebViewClient() {
                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    view.loadUrl(url);
                    return true;
                }

                @Override
                public void onPageFinished(WebView view, String url) {
                    if (progressDialog.isShowing()) {
                        new Handler().postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                progressDialog.dismiss();
                            }
                        }, 2000);

                    }
                }

                @Override
                public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                    //Show error message
                }
            });
            myWebView.loadUrl("http://maps.google.com/maps?saddr=" + latitude + "," + longitude + "&daddr=" + deignationLat + "," + deignationLong);

Or you can refer the link: http://www.journaldev.com/13373/android-google-map-drawing-route-two-points 或者您可以参考链接: http//www.journaldev.com/13373/android-google-map-drawing-route-two-points

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想创建一个Android应用程序,其中包含提供路线的地图,但不包括Google地图 - I want to make an Android app with a map that provides directions, but not Google Maps 如何为Android Google Maps在两个位置之间实施路线搜索 - How to implement directions search between two locations for android google maps 谷歌地图方向 API 空白回复 - Google Maps Directions API blank response 在 Android 应用程序中使用谷歌地图路线 - Using Google Maps Directions in Android App 通过 Android 的意图启动 Google Maps Directions - Launching Google Maps Directions via an intent on Android 如何在Android Google Maps API中设置WMS请求图层的不透明度 - How do I set the opacity of a WMS requested layer in Android Google Maps API 如何在Java代码中使用Google Maps API来获取指定位置的坐标? - How do I use Google Maps API in a Java code to fetch coordinates of specified location? 如何将Google Directions API中的“步骤”解析为Java(Android) - How to parse “steps” from the google directions API to java (android) 如何在Android中的Java中向Google Map Api添加路线? - How to add directions to Google Map Api in java in Android? Android:可以在模拟器上使用Google Maps API吗? - Android: Is it possible to use Google Maps API on emulator?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM