android地图定位

简言之测试一下andriod惨遭之地形图应用,没悟出一个很小应用为花了累累之事,记录转,以备查.

率先使修改AndroidManifest.xml文件:

<!– 加入引用库 –>

<uses-library android:name=”com.google.android.maps” /> 

<!– 加入权限 –>

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

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

<uses-permission android:name=”android.permission.INTERNET” />

 

然后修改Activity,注意要从MapActivity继承:

public class MainActivity extends MapActivity { …  }

下面是activity的一个简短示例:

public class MainActivity extends MapActivity {

private MapView mMapView;

private MapController
mMapContraoller;

private GeoPoint mGeoPoint=new
GeoPoint(30659259,104065762);

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        

        mMapView=(MapView)findViewById(R.id.MapView01);

        mMapView.setTraffic(true);

        mMapView.setEnabled(true);

        mMapView.setClickable(true);

        

        mMapContraoller=mMapView.getController();

        

        mMapContraoller.setZoom(12);

        mMapContraoller.animateTo(mGeoPoint);

    }

@Override  

protected boolean
isRouteDisplayed() {

// TODO Auto-generated method stub

return false;

}

 

activity的资源文件中填加mapview:

<com.google.android.maps.MapView

android:id=”@+id/MapView01″

android:layout_width=”fill_parent”

android:layout_height=”fill_parent”

android:apiKey=”067_6YH5q7XFvCHGX8HeK9FQf9pMrzQsax4hqOw”

/> 

 

 注意:

android:apiKey=”067_6YH5q7XFvCHGX8HeK9FQf9pMrzQsax4hqOw”

假使和谐失去申请,然后加上. 

相关文章