【问题标题】:Google API Map Zoom谷歌 API 地图缩放
【发布时间】:2012-04-09 10:41:42
【问题描述】:
 import com.google.android.maps.MapActivity;
 import com.google.android.maps.MapView;

 import android.os.Bundle;

 public class Map2Activity extends MapActivity {
/** Called when the activity is first created. */
MapView map;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    map = (MapView)findViewById(R.id.mvMain);
    map.setBuiltInZoomControls(true);
}

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

清单文件

<uses-sdk android:minSdkVersion="8"/>
<uses-permission android:name="android.permission.INTERNET"/>

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <uses-library android:name="com.google.android.maps" />

main.xml

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

<com.google.android.maps.MapView
             android:layout_width="fill_parent"
             android:layout_height="fill_parent"
             android:apiKey="01VR0PIBfyfgbR5DlOlcEBPG9F5WfE7ZBPg"
             android:tag="@+id/mvMain"
             android:enabled="true"
             android:clickable="true" />

</LinearLayout>

我没有得到这两个语句的地图(强行关闭应用程序) 地图 = (MapView)findViewById(R.id.mvMain); map.setBuiltInZoomControls(true);
如果它必须起作用,我需要给予什么?

【问题讨论】:

    标签: android map zooming


    【解决方案1】:

    改变

    android:tag="@+id/mvMain"
    

    android:id="@+id/mvMain"
    

    【讨论】:

      【解决方案2】:

      使用它:--main.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">
          <RelativeLayout android:layout_width="fill_parent"
                  android:layout_height="fill_parent">
                  <com.google.android.maps.MapView
                      android:id="@+id/mapView" android:layout_width="fill_parent"
                      android:layout_height="fill_parent" android:enabled="true"
                      android:clickable="true" android:apiKey="0zWsBUUrp7PHyoVnmV5qN5nHhXhZ-VJHhlnjYig" />
                  <LinearLayout android:id="@+id/zoom"
                      android:layout_width="wrap_content" android:layout_height="wrap_content"
                      android:layout_alignParentBottom="true"
                      android:layout_centerHorizontal="true" />
              </RelativeLayout>
       </LinearLayout>
      

      在你的活动中使用它--

        LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);  
          View zoomView = mapView.getZoomControls(); 
      
          zoomLayout.addView(zoomView, 
              new LinearLayout.LayoutParams(
                  LayoutParams.WRAP_CONTENT, 
                  LayoutParams.WRAP_CONTENT)); 
          mapView.displayZoomControls(true);
      

      希望它会帮助你..

      【讨论】:

        猜你喜欢
        • 2012-03-10
        • 2012-12-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-19
        • 2012-09-08
        • 2012-11-06
        相关资源
        最近更新 更多