将标记添加到检索到的位置

时间:2010-03-30 12:19:38

标签: android

我已使用以下代码在我的应用中显示地图。我从数据库中检索了信息并显示了地图。现在我想将标记添加到检索到的位置......

googleMao.java

public class googleMap extends MapActivity{
    private MapView mapView;
       private MapController mc;
       GeoPoint p;
       long s;
       Cursor cur;
       SQLiteDatabase db;
       createSqliteHelper csh;
       String query;

     @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.map);
            // String query = getIntent().getStringExtra("value");
            // here is calling the map string query
            s = getIntent().getLongExtra("value",2);
            map();
            mapView = (MapView) findViewById(R.id.mapview1);       
            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);
           mapView.setBuiltInZoomControls(true);
            mc = mapView.getController();
            String coordinates[] = {"1.352566007", "103.78921587"};
            double lat = Double.parseDouble(coordinates[0]);
            double lng = Double.parseDouble(coordinates[1]);

            Geocoder geoCoder = new Geocoder(this, Locale.getDefault());    
            try {
                List<Address> addresses = geoCoder.getFromLocationName(query, 5);
                String add = "";
                if (addresses.size() > 0) {
                    p = new GeoPoint(
                            (int) (addresses.get(0).getLatitude() * 1E6), 
                            (int) (addresses.get(0).getLongitude() * 1E6));
                    mc.animateTo(p);    
                    mapView.invalidate();
                    mc.setZoom(6);
                }    
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

       @Override
       protected boolean isRouteDisplayed() {
          // Required by MapActivity
          return false;
       }
       public void map()
       {
           String[] str={"type"};
           int[] i={R.id.type};
           csh=new createSqliteHelper(this);
           db=csh.getReadableDatabase();
           cur=db.rawQuery("select type from restaurants where _id="+s,null);
           if(cur.moveToFirst())
           {
              query = cur.getString(cur.getColumnIndex("type"));
           }
       }

}

1 个答案:

答案 0 :(得分:0)

您需要为此创建ItemizedOverlay。我的书籍Here is one sample project显示ItemizedOverlay添加了MapView