tags:

views:

48

answers:

1

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 qurry;
     @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.map);
            // String qurry=getIntent().getStringExtra("value");
            //here is calling the map string qurry
            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(qurry,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())
           {
              qurry=cur.getString(cur.getColumnIndex("type"));
           }
       }

}
A: 

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

CommonsWare
I have seen you example but the project it not getting executed...I have the following errors in logcat.07-31 10:23:36.264: ERROR/AndroidRuntime(839): Uncaught handler: thread main exiting due to uncaught exception07-31 10:23:36.293: ERROR/AndroidRuntime(839): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.MapMarker/com.MapMarker.MapMarker}: java.lang.ClassNotFoundException: com.MapMarker.MapMarker in loader dalvik.system.PathClassLoader@43760ac0
Rahul Varma
That error seems straightforward: you are missing com.MapMarker.MapMarker from your application. Figure out why that is not being included in your APK file, or if there is no class by that name, fix your manifest.
CommonsWare
Fixed the problem. I have obtained locations from database through a query. Can you help me adding marker to the program that i listed above???
Rahul Varma
Or can you help me with an example of marking a location from the values returned from the database
Rahul Varma