开发者

Adding marker to the retrieved location

开发者 https://www.devze.com 2022-12-25 16:23 出处:网络
I have displayed the map in my app by using the following code. I have retrieved info from the database and displayed the map. Now i want to add marker to the retrieved location...

I have displayed the map in my app by using the following code. I have retrieved info from the database and displayed the map. Now i want to add marker to the retrieved location...

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.pa开发者_开发问答rseDouble(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"));
           }
       }

}


You need to create an ItemizedOverlay for that. Here is one sample project from my books that shows adding an ItemizedOverlay to a MapView.

0

精彩评论

暂无评论...
验证码 换一张
取 消