You are here:   Home >> Program >> Eclipse developed Android, Hello, MapView (study 5)

Eclipse developed Android, Hello, MapView (study 5)

Hello, MapView

Learning Address: http://androidappdocs.appspot.com/guide/tutorials/views/hello-mapview.html

HelloItemizedOverlay.java Code

1
  package com.example.test; import java.util.ArrayList; import android.graphics.drawable.Drawable; import com.google.android.maps.ItemizedOverlay; import com.google.android.maps.OverlayItem; public class HelloItemizedOverlay extends ItemizedOverlay (private ArrayList <OverlayItem> mOverlays = new ArrayList <OverlayItem> (); public HelloItemizedOverlay (Drawable defaultMarker) (super (boundCenterBottom (defaultMarker ));// TODO Auto-generated constructor stub) @ Overridepublic int size () (return mOverlays. size ();) public void addOverlay (OverlayItem overlay) (mOverlays.add (overlay); populate ();}Overrideprotected OverlayItem createItem (int i) (return mOverlays.get (i);))

HelloMapView1.java Code

1
  package com.example.test; import java.util.List; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.widget.LinearLayout; import android.widget.ZoomControls; 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 HelloMapView1 extends MapActivity (LinearLayout linearLayout; MapView mapView; ZoomControls mZoom; List <Overlay> mapOverlays; Drawable drawable; HelloItemizedOverlay itemizedOverlay; / ** Called when the activity is first created. * / @ Override public void onCreate (Bundle savedInstanceState) (super . onCreate (savedInstanceState); setContentView (R.layout.main); mapView = (MapView) findViewById (R.id.mapview); mapView.setBuiltInZoomControls (true); mapOverlays = mapView.getOverlays (); drawable = this.getResources ( ). getDrawable (R.drawable.androidmarker); itemizedOverlay = new HelloItemizedOverlay (drawable); GeoPoint point = new GeoPoint (19240000, -99120000); OverlayItem overlayitem = new OverlayItem (point, "", ""); itemizedOverlay.addOverlay ( overlayitem); mapOverlays.add (itemizedOverlay);) @ Override protected boolean isRouteDisplayed () (return false;))

Layout-> mail.xml

1
  <? xml version = "1.0" encoding = "utf-8"?> <RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: id = "@ + id / mainlayout "android: orientation =" vertical "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: clickable =" true "android: apiKey =" Your Maps API Key "/> <LinearLayout android: id =" @ + id / zoomview "android: layout_width =" wrap_content "android: layout_height = "wrap_content" android: layout_alignBottom = "@ id / mapview" android: layout_centerHorizontal = "true "/></ RelativeLayout>

Implementation of the android Application, found that google maps can not be displayed, please know the cause of the friend told my, thank you.

Permalink: Code Library » http://www.ucosoft.com/eclipse-developed-android-mapview-study-2.html

Related Posts

Leave a Reply