2016-01-27 100 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地图应用程序本身的外部进行。 –

相关问题