【问题标题】:Opening Google Directions API internally Android Studio在 Android Studio 内部打开 Google Directions API
【发布时间】:2016-05-04 16:11:52
【问题描述】:

我目前正在 Android Studio 中开发一个应用程序,并且我在应用程序中包含了 Google Maps API 和 Google Directions API。我在我的应用程序中包含了一个按钮,它允许用户被引导到他们选择的位置。

以下代码使用 Google Maps API,在应用程序中打开 Google Maps,但在地图上显示标记,但不提供前往该地点的方向:

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);

    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    // Add a marker at the Oval and move the camera
    LatLng oval = new LatLng(53.3484013,-6.2605243);
    mMap.addMarker(new MarkerOptions().position(oval).title("Oval Pub"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(oval));

以下代码使用 Google Directions API 并为用户提供前往所选目的地的指南:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);


    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    Uri gmmIntentUri = Uri.parse("google.navigation:q=The+Oval+Bar,+Dublin+Ireland");
    Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
    mapIntent.setPackage("com.google.android.apps.maps");
    startActivity(mapIntent);

唯一的问题是上述与 Google Directions API 相关的代码会在我的应用程序之外打开 Google Maps 应用程序。我想知道如何让它在应用程序本身中打开。

【问题讨论】:

  • 您需要解析从 Directions Api 接收到的数据并将路径绘制到 MapView 上。

标签: android api google-maps android-studio google-maps-api-3


【解决方案1】:

您应该使用片段 com.google.android.gms.maps.MapFragment,如 Lars Vogel 这篇精彩文章中所示:http://www.vogella.com/tutorials/AndroidGoogleMaps/article.html

【讨论】:

  • 谷歌地图在我的应用程序中运行,问题是我需要谷歌路线在我的应用程序中运行。当我点击按钮时,它会显示到我选择的位置的路线,但它会在 Google 地图应用程序本身的外部进行。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多