2016-01-27 33 views
0

我目前正在Android Studio中開發應用程序,並且在應用程序中包含Google Maps API和Google Directions API。我在我的應用中添加了一個按鈕,允許用戶引導到他們選定的位置。在內部打開Goog​​le路線API Android Studio

下面的代碼使用谷歌地圖API的應用程序中打開了谷歌地圖,但顯示在地圖上的標記,而不給予指示,那個地方:

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)); 

下面的代碼使用谷歌地圖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); 

是涉及到谷歌地圖API上面的代碼唯一的問題,我打開應用程序之外的谷歌地圖應用程序。我想知道如何在應用程序本身中打開它。

+0

你需要分析你從路線阿比接收數據並繪製從它到MapView的路徑。 – ikbal

回答

0

您應該使用片段com.google.android.gms.maps.MapFragment如圖所示這個偉大的Lars沃格爾文章:http://www.vogella.com/tutorials/AndroidGoogleMaps/article.html

+0

谷歌地圖運行我的應用程序,問題是我需要谷歌方向在我的應用程序內運行。當我點擊該按鈕時,它會提示我所選位置的方向,但它會在Google地圖應用程序本身的外部進行。 –

相關問題