Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

I just want Point A to have a line direction going to Point B.

like image 899
Jhay Cruz Avatar asked Oct 29 '22 06:10

Jhay Cruz


2 Answers

Yes it is possible to intergrate direcitons api with map. There is no need to write your own API. You can achieve this very easily. With Google android api V2 there is no need to draw canvas. Adding things in it is very easy.

Please read here for Google Maps https://developers.google.com/maps/documentation/android/start

and for directions

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

During the process you have any specific problem then please ask that.

Thanks,

like image 108
geekfreak.xyz Avatar answered Nov 15 '22 04:11

geekfreak.xyz


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.

This is the code snippet for load google map in 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

like image 25
EKN Avatar answered Nov 15 '22 04:11

EKN