2012-09-27 44 views
2

显示Google地图,但在加载地图时,标题栏消失。 有没有解决方案来显示标题栏?如何在加载谷歌地图时显示标题栏

private void calc_short_Distance() { 
     String uri = "http://maps.google.com/maps?saddr=" + currentLatitude+","+currentLongitude+"&daddr="+fixedLatitude+","+fixedLongitude; 
     Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)); 
     intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"); 
     //***Title bar displayed upto here and after loading intent it disappear 
     startActivity(intent); 


    } 

清单代码是here和主活动类是here

+1

您应该将您的代码(xml和java)作为您的问题的一部分发布 - 但不是整个代码,只有相关部分。 –

+0

@AleksG我已经添加了代码.. – nKandel

+1

您正在打开默认浏览器或默认地图应用程序。它不是你的应用程序的一部分,所以你不能在其他应用程序中显示标题栏 –

回答

1

您的标题栏未显示在地图上,因为您将地图作为地图应用程序打开。现在,当地图显示时,它不再是您的应用程序,而是Google的应用程序。如果你想控制地图的显示方式,那么你需要上有一个MapView创建自己的活动,并使用MapView API来绘制自己的路线,等你的伪XML可能看起来像这样:

<LinearLayout android:orientation="vertical"> 
    <!-- 
    Whatever you want at the top 
    --> 

    <MapView android:layout_width="match_parent" android:layout_height="match_parent" /> 
</LinearLayout> 

然后,您需要通过扩展MapActivity并将此XML用于其内容视图来创建活动。然后,您可以使用MapView API来显示所需的任何叠加层。您还需要获取API密钥以与地图一起使用。查看Google's MapView tutorial了解更多关于如何编码此活动的信息。

一旦你有地图活动,然后使用意图启动这个地图活动,而不是谷歌地图应用程序。