0

I want to use Google Maps Android API and Google Maps Direction API , the first one obviously for google maps and the latter for calculating distance between them , is it possible to use them , is so then how , if there are examples , I would appreciate if you could paste few links for the same. Thanks in Advance.

1 Answers1

0

It is possible, because you need an Android API key for loading a map on your activity and Server Key for Getting the Direction between two points.

google_maps_api.xml

<resources>
<!--
TODO: Before you run your application, you need a Google Maps API key.
To get one, follow this link, follow the directions and press "Create" at the end:
https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=FA:7B:BC:CE:B9:9E:4C:81:3D:91:35:B7:60:5E:9A:AA:B8:A5:B6:66%3Bcom.itshareplus.googlemapdemo
You can also add your credentials to an existing key, using this line:
FA:7B:BC:CE:B9:9E:4C:81:3D:91:35:B7:60:5E:9A:AA:B8:A5:B6:66;com.itshareplus.googlemapdemo
Alternatively, follow the directions here:
https://developers.google.com/maps/documentation/android/start#get-key
Once you have your key (it starts with "AIza"), replace the "google_maps_key"
string in this file.
-->
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">YOUR_API_KEY</string>
</resources>

DirectionFinder.java

public class DirectionFinder {
private static final String DIRECTION_URL_API = "https://maps.googleapis.com/maps/api/directions/json?";
private static final String GOOGLE_API_KEY = "SERVER_KEY";
private DirectionFinderListener listener;
private String origin;
private String destination;
.....

If you are creating a nagivation map, kindly check this SO question.

Sources:

  1. http://googlegeodevelopers.blogspot.com/2015/06/code-road-android-app-bike-with-map-on.html
  2. https://developers.google.com/maps/documentation/android-api/
  3. https://github.com/hiepxuan2008/GoogleMapDirectionSimple
  4. https://www.youtube.com/watch?v=CCZPUeY94MU
Community
  • 1
  • 1
Mr.Rebot
  • 6,703
  • 2
  • 16
  • 91