Adding marker to the retrieved location
Posted
by Rahul Varma
on Stack Overflow
See other posts from Stack Overflow
or by Rahul Varma
Published on 2010-03-30T12:19:37Z
Indexed on
2010/03/30
12:23 UTC
Read the original article
Hit count: 415
android
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"));
}
}
}
© Stack Overflow or respective owner