首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

Google Map(2)

2012-09-24 
Google Map(二)在Google Map(一)??另外还要开通网络权限,在manifest的child节点中添加如下:AndroidManifes

Google Map(二)

在Google Map(一)

?

?另外还要开通网络权限,在manifest的child节点中添加如下:

AndroidManifest.xml完整代码如下:

??

2、打开res/layout/main.xml,在里面添加com.google.android.maps.MapView节点:

import java.util.List;import android.graphics.drawable.Drawable;import android.os.Bundle;import com.google.android.maps.GeoPoint;import com.google.android.maps.MapActivity;import com.google.android.maps.MapView;import com.google.android.maps.Overlay;import com.google.android.maps.OverlayItem;public class googlemap1 extends MapActivity {    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        MapView mapView = (MapView) findViewById(R.id.mapview);        //设置mapView显示用于缩放的工具条        mapView.setBuiltInZoomControls(true);        //调用mapView对象的getOverlays()方法,用于得到所有的图层对象        List<Overlay> mapOverlays = mapView.getOverlays();        Drawable drawable = this.getResources().getDrawable(R.drawable.icon);//引用android自带的图片        HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable,this);                //创建一个GeoPoint对象,通过经纬度指定地图上的一个点        GeoPoint point = new GeoPoint(19240000,-99120000);        //创建一个OverLayItem对象        OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!");        //将创建好的OverlayItem对象添加到HelloItemizedOverlay对象中        itemizedoverlay.addOverlay(overlayitem);        //将HelloItemizedOverlay对象添加到mapView        mapOverlays.add(itemizedoverlay);    }@Overrideprotected boolean isRouteDisplayed() {return false;}}