【问题标题】:Testing functionality of google maps view inside android app在android应用程序中测试谷歌地图视图的功能
【发布时间】:2012-10-02 12:32:20
【问题描述】:

您好,感谢您的关注。我正在开发我的第一个 android 应用程序。在其中一个标签中,我想要一个功能版本的谷歌地图。如你所见,我正在路上。但是我不知道如何使用模拟器放大/输入导航地址等,以查看它是否正常运行。

这是布局xml:

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     >

    <com.google.android.maps.MapView
     android:id="@+id/myMapView"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:enabled="true"
     android:clickable="true"
     android:apiKey="myapikey"
   />

 </LinearLayout>

还有我的地图活动的java:

 import android.os.Bundle;

 import com.google.android.maps.MapActivity;

 public class MapsActivity extends MapActivity {
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.maps_layout);
     }

     @Override
     protected boolean isRouteDisplayed() {
         // TODO Auto-generated method stub
         return false;
     }
 }

【问题讨论】:

    标签: java android eclipse android-emulator android-mapview


    【解决方案1】:

    要打开缩放,您应该执行以下操作:

    public class MapsActivity extends MapActivity {
         private MapView map;
         public void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
             setContentView(R.layout.maps_layout);
             map = (MapView) findViewById(R.id.map);
             map.setBuiltInZoomControls(true);
         }
    

    我不确定导航,需要覆盖

    protected boolean isRouteDisplayed() {
            // TODO Auto-generated method stub
            return false;
        }
    

    是这个,因此您无法显示到搜索地点的路线。

    【讨论】:

      【解决方案2】:
      @Override
      public void onCreate(Bundle savedInstanceState) 
      {
          super.onCreate(savedInstanceState);
          TextView myLocationText = (TextView) findViewById(R.id.myLocationText);
          setContentView(R.layout.map);        
      
          //make available zoom controls
          mapView.setBuiltInZoomControls(true);
      
          // zoom 1 is top world view
          controller.setZoom(17);
      }
      

      您还可以使用最后一行对地图启动时的缩放进行硬编码

      【讨论】:

        猜你喜欢
        • 2013-09-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-29
        • 1970-01-01
        • 1970-01-01
        • 2014-09-17
        相关资源
        最近更新 更多