【发布时间】:2016-10-17 00:29:22
【问题描述】:
我想使用 Google Maps Android API 和 Google Maps Direction API,第一个显然是用于谷歌地图,后者用于计算它们之间的距离,是否可以使用它们,那么如何,如果有例子,如果您能粘贴一些相同的链接,我将不胜感激。 提前致谢。
【问题讨论】:
标签: android google-maps android-studio google-api
我想使用 Google Maps Android API 和 Google Maps Direction API,第一个显然是用于谷歌地图,后者用于计算它们之间的距离,是否可以使用它们,那么如何,如果有例子,如果您能粘贴一些相同的链接,我将不胜感激。 提前致谢。
【问题讨论】:
标签: android google-maps android-studio google-api
这是可能的,因为您需要一个 Android API 密钥来在您的活动上加载地图,并需要一个服务器密钥来获取两点之间的方向。
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;
.....
如果您正在创建导航地图,请查看此SO question。
【讨论】: