public void addOverLays(){
String [] coordinates = {"30.084262490272522","31.33625864982605" ,"30.084123015403748", "51.5002" , "-0.1262","31.337149143218994"};
double lat = 30.084262490272522, lat2 = 51.5002,lat3=30.084123015403748;
double log = 31.33625864982605, log2 = -0.1262,log3=31.337149143218994;
p = new GeoPoint((int) (lat * 1E6), (int) (log * 1E6));
p2 = new GeoPoint( (int) (lat2 * 1e6), (int) (log2 * 1e6));
p3 = new GeoPoint( (int) (lat3 * 1E6), (int) (log3 * 1E6));
mapOverlays = mapView.getOverlays();
drawable = this.getResources().getDrawable(R.drawable.icon);
drawable2 = this.getResources().getDrawable(R.drawable.pushpin);
drawable3 = this.getResources().getDrawable(R.drawable.ballon);
itemizedOverlay = new HelloItemizedOverlay(drawable,this);
itemizedOverlay2 = new HelloItemizedOverlay(drawable2,this);
itemizedOverlay3 = new HelloItemizedOverlay(drawable3,this);
OverlayItem overlayitem = new OverlayItem(p, "Cairo", " over1");
OverlayItem over2 = new OverlayItem(p2, "ulm", "over2");
OverlayItem over3 = new OverlayItem(p3, "offff", "over3");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
itemizedOverlay2.addOverlay(over2);
mapOverlays.add(itemizedOverlay2);
itemizedOverlay2.addOverlay(over3);
mapOverlays.add(itemizedOverlay3);
Why can't I add 3 items due to
p = new GeoPoint((int) (lat * 1E6), (int) (log * 1E6));
p2 = new GeoPoint( (int) (lat2 * 1e6), (int) (log2 * 1e6));
p3 = new GeoPoint( (int) (lat3 * 1E6), (int) (log3 * 1E6));
can't make 1E6 & 1e6 what other I have to do?!!
you might have a casting issue, hard to tell. Try using this utility method:
public static GeoPoint calculateGeoPoint(double latitude, double longitude) {
Double latE6 = latitude * 1E6;
Double lngE6 = longitude * 1E6;
return new GeoPoint(latE6.intValue(), lngE6.intValue());
}
It's worked reliably for me in tested production code.
Related
I followed one of the tutarial about google maps. Unfortunately it is using google maps v1. Now I'm working on an old android application upgrading it from the Google API v1 to v2. How can I do this on Google Maps API v2? Need same help here.
public class PlacesMapActivity extends MapActivity {
PlacesList nearPlaces;
MapView mapView;
List<Overlay> mapOverlays;
AddItemizedOverlay itemizedOverlay;
GeoPoint geoPoint;
MapController mc;
double latitude;
double longitude;
OverlayItem overlayitem;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_places_map);
Intent i = getIntent();
String user_latitude = i.getStringExtra("user_latitude");
String user_longitude = i.getStringExtra("user_longitude");
nearPlaces = (PlacesList) i.getSerializableExtra("near_places");
mapView = (MapView) findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(true);
mapOverlays = mapView.getOverlays();
geoPoint = new GeoPoint((int) (Double.parseDouble(user_latitude) * 1E6),
(int) (Double.parseDouble(user_longitude) * 1E6));
Drawable drawable_user = this.getResources()
.getDrawable(R.drawable.mark_red);
itemizedOverlay = new AddItemizedOverlay(drawable_user, this);
overlayitem = new OverlayItem(geoPoint, "Your Location",
"That is you!");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
itemizedOverlay.populateNow();
Drawable drawable = this.getResources()
.getDrawable(R.drawable.mark_blue);
itemizedOverlay = new AddItemizedOverlay(drawable, this);
mc = mapView.getController();
int minLat = Integer.MAX_VALUE;
int minLong = Integer.MAX_VALUE;
int maxLat = Integer.MIN_VALUE;
int maxLong = Integer.MIN_VALUE;
if (nearPlaces.results != null) {
// loop through all the places
for (Place place : nearPlaces.results) {
latitude = place.geometry.location.lat; // latitude
longitude = place.geometry.location.lng; // longitude
geoPoint = new GeoPoint((int) (latitude * 1E6),
(int) (longitude * 1E6));
overlayitem = new OverlayItem(geoPoint, place.name,
place.vicinity);
itemizedOverlay.addOverlay(overlayitem);
// calculating map boundary area
minLat = (int) Math.min( geoPoint.getLatitudeE6(), minLat );
minLong = (int) Math.min( geoPoint.getLongitudeE6(), minLong);
maxLat = (int) Math.max( geoPoint.getLatitudeE6(), maxLat );
maxLong = (int) Math.max( geoPoint.getLongitudeE6(), maxLong );
}
mapOverlays.add(itemizedOverlay);
// showing all overlay items
itemizedOverlay.populateNow();
}
mapView.getController().zoomToSpan(Math.abs( minLat - maxLat ), Math.abs( minLong - maxLong ));
mc.animateTo(new GeoPoint((maxLat + minLat)/2, (maxLong + minLong)/2 ));
mapView.postInvalidate();
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
}
You may want to check out this post - Android Maps API v1 to v2. It seems to have the same question you have.
i want to display my location and destination location at map. the problem is that the destination location always point at same location even if i change another destination long and lat...
here is the code
protected void tampilkanPosisikeMap(Location newLocation) {
List<Overlay> overlays = mapView.getOverlays();
if (overlays.size() > 0) {
for (Iterator iterator = overlays.iterator(); iterator.hasNext();) {
iterator.next();
iterator.remove();
}
}
GeoPoint geopoint = new GeoPoint(
(int) (newLocation.getLatitude() * 1E6), (int) (newLocation
.getLongitude() * 1E6));
GeoPoint myposition = geopoint;
Location locationA = new Location("point A");
Location locationB = new Location("point B");
locationA.setLatitude(geopoint.getLatitudeE6() / 1E6);
locationA.setLongitude(geopoint.getLongitudeE6() / 1E6);
Drawable icon1 = getResources().getDrawable(R.drawable.user);
icon1.setBounds(0, 0, icon1.getIntrinsicWidth(), icon1
.getIntrinsicHeight());
MyItemizedOverlay overlay1 = new MyItemizedOverlay(icon1, this);
OverlayItem item1 = new OverlayItem(geopoint, "Posisi Anda", "Lat:"
+ locationA.getLatitude() + "\nLng:" + locationA.getLongitude());
overlay1.addItem(item1);
mapView.getOverlays().add(overlay1);
String lat2,longi2;
String nama_rs;String alamat_rs;
nama_rs = getIntent().getExtras().getString("namarsakit");
alamat_rs = getIntent().getExtras().getString("alamatrsakit");
lat2 = getIntent().getExtras().getString("lat");
longi2 = getIntent().getExtras().getString("longi");
Double lintang_rs = Double.parseDouble(lat2);
Double bujur_rs = Double.parseDouble(longi2);
GeoPoint geopoint1 = new GeoPoint(
(int) (lintang_rs * 1E6),
(int) (bujur_rs * 1E6));
locationB.setLatitude(geopoint1.getLatitudeE6() / 1E6);
locationB.setLongitude(geopoint1.getLongitudeE6() / 1E6);
DecimalFormat formatData = new DecimalFormat("#.#");
float distance = (float) locationA.distanceTo(locationB) / 1000;
String jarak;
jarak = String.valueOf(formatData.format(distance));
Drawable icon = getResources().getDrawable(R.drawable.marker); //
icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon
.getIntrinsicHeight());
MyItemizedOverlay overlay = new MyItemizedOverlay(icon, this); //
OverlayItem item = new OverlayItem(geopoint1, nama_rs, //
alamat_rs
+ "\n\nJarak dari Posisi Anda : " + jarak + " km");
overlay.addItem(item);
mapView.getOverlays().add(overlay);
Toast.makeText(MapDetailActivity.this,"nama = "+nama_rs+"lat tujuan= "+lintang_rs+"long tujuan = "+bujur_rs, Toast.LENGTH_SHORT).show();
mapView.getController().animateTo(geopoint1);
}
this is the destination code from above :
String lat2,longi2;
String nama_rs;String alamat_rs;
nama_rs = getIntent().getExtras().getString("namarsakit");
alamat_rs = getIntent().getExtras().getString("alamatrsakit");
lat2 = getIntent().getExtras().getString("lat");
longi2 = getIntent().getExtras().getString("longi");
Double lintang_rs = Double.parseDouble(lat2);
Double bujur_rs = Double.parseDouble(longi2);
GeoPoint geopoint1 = new GeoPoint(
(int) (lintang_rs * 1E6),
(int) (bujur_rs * 1E6));
locationB.setLatitude(geopoint1.getLatitudeE6() / 1E6);
locationB.setLongitude(geopoint1.getLongitudeE6() / 1E6);
DecimalFormat formatData = new DecimalFormat("#.#");
float distance = (float) locationA.distanceTo(locationB) / 1000;
String jarak;
jarak = String.valueOf(formatData.format(distance));
Drawable icon = getResources().getDrawable(R.drawable.marker); //
icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon
.getIntrinsicHeight());
MyItemizedOverlay overlay = new MyItemizedOverlay(icon, this); //
OverlayItem item = new OverlayItem(geopoint1, nama_rs, //
alamat_rs
+ "\n\nJarak dari Posisi Anda : " + jarak + " km");
overlay.addItem(item);
mapView.getOverlays().add(overlay);
Toast.makeText(MapDetailActivity.this,"nama = "+nama_rs+"lat tujuan= "+lintang_rs+"long tujuan = "+bujur_rs, Toast.LENGTH_SHORT).show();
mapView.getController().animateTo(geopoint1);
For You to be able to show your Current location you must tap on to GPS location provider or Network Location provider. Looking at your code I cannot see any of this. Please note on emulator DDMS will default to a specific location. unless you supply one yourself
enter code here
05-31 00:26:46.295: ERROR/AndroidRuntime(4111): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2685)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): FATAL EXCEPTION: main
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): java.lang.RuntimeException: Unable to start activity ComponentInfo{yaraby.y/yaraby.y.yarab}: java.lang.NullPointerException
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2685)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at a ndroid.app.ActivityThread.access$2300(ActivityThread.java:126)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2038)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at android.os.Handler.dispatchMessage(Handler.java:99)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at android.os.Looper.loop(Looper.java:123)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at android.app.ActivityThread.main(ActivityThread.java:4633)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at java.lang.reflect.Method.invokeNative(Native Method)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at java.lang.reflect.Method.invoke(Method.java:521)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at dalvik.system.NativeStart.main(Native Method)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): Caused by: java.lang.NullPointerException
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at yaraby.y.yarab.onCreate(yarab.java:92)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2633)
05-31 00:32:08.465: ERROR/AndroidRuntime(4301): ... 11 more
Yaraby Code
enter code here
public class yaraby extends Activity {
/** Called when the activity is first created. */
String sentence,sentence1, modifiedSentence;;
EditText inputfld, txt;
TextView Text;
Button Enter, Connect, next;
Socket clientSocket;
DataOutputStream outToServer;
BufferedReader inFromServer ;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
inputfld=(EditText)findViewById(R.id.input);
Text=(TextView)findViewById(R.id.view);
Enter=(Button)findViewById(R.id.enter);
Connect=(Button)findViewById(R.id.connect);
Text.append( "\n about to create a socket");
txt=(EditText)findViewById(R.id.txt);
next = (Button) findViewById(R.id.Button01);
next.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
try{
Text.append("PPPPP");
Intent i = new Intent(yaraby.this, yarab.class);
startActivity(i);
Text.append("OPS");
}
catch(Error e){
Log.e("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", e.getMessage());
Text.append("ofa7ay");
}
}});
}
public void appendText(View view){
Text.append( "\n In chat ");
try{
sentence=inputfld.getText().toString();
sentence1="ingyyyy";
Text.append( "\n DataStream creating");
outToServer.writeBytes(sentence);
outToServer.writeBytes(sentence1);
Thread.sleep(1000);
modifiedSentence = inFromServer.readLine();
Text.append(modifiedSentence);
inputfld.setText(null);
}
catch(Exception modifiedsentence){
Text.append("Exception");
}
}
public void connect(View view){
try{
clientSocket= new Socket("192.168.1.6",54611);
Text.append( "\n created a socket");
outToServer = new DataOutputStream(clientSocket.getOutputStream());
Text.append( "\n created a datastream");
inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
Text.append( "\n created a bufferReader");
outToServer = new DataOutputStream(clientSocket.getOutputStream());
}catch(Exception e){
System.out.println("Error");
}
}
yarab code
enter code here
package yaraby.y;
public class yarab extends MapActivity
{
Socket clientSocket;
TextView Text;
private MapView mapView;
private MapController mc;
DataOutputStream outToServer;
BufferedReader inFromServer ;
Button start;
int error = 50;
GeoPoint p, p2;
List<Overlay> mapOverlays;
Drawable drawable, drawable2;
HelloItemizedOverlay itemizedOverlay, itemizedOverlay2;
LocationManager locationManager;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/* Use the LocationManager class to obtain GPS locations */
LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
0, mlocListener);
mapView = (MapView) findViewById(R.id.mapView);
// enable Street view by default
mapView.setStreetView(true);
// enable to show Satellite view
mapView.setSatellite(true);
// enable to show Traffic on map
// mapView.setTraffic(true);
mapView.setBuiltInZoomControls(true);
mc = mapView.getController();
mc.setZoom(12);
addOverLays();
start= (Button) findViewById(R.id.start);
}
public void addOverLays() {
String[] coordinates = { "31.216487288475037", "29.932637214660645",
"30.084123015403748", "51.5002", "-0.1262",
"31.337149143218994" };
double lat = 29.98739718380868, lat2 = 29.987810254096985;
double log = 31.442527770886084, log2 = 31.44258677959442;
p = new GeoPoint((int) (lat * 1E6), (int) (log * 1E6));
p2 = new GeoPoint((int) (lat2 * 1E6 ), (int) (log2 * 1E6 ));
p3 = new GeoPoint((int) (lat3 * 1e6), (int) (log3 * 1e6));
p4 = new GeoPoint((int) (lat4 * 1e6), (int) (log4 * 1e6));
p5 = new GeoPoint((int) (lat14* 1e6), (int) (log14 * 1e6));
p6 = new GeoPoint((int) (lat8 * 1e6), (int) (log8 * 1e6));
p7 = new GeoPoint((int) (t1* 1e6), (int) (log15 * 1e6));
p8 = new GeoPoint((int) (lat5 * 1e6), (int) (log5 * 1e6));
p9 = new GeoPoint((int) (lat6 * 1e6), (int) (log6 * 1e6));
p10=new GeoPoint( (int) (t4 * 1e6), (int) (log12 * 1e6));
p11=new GeoPoint( (int) (t2* 1e6), (int) (log14 * 1e6));
p12=new GeoPoint( (int) (t3* 1e6), (int) (log5 * 1e6));
p13=new GeoPoint( (int) (t5* 1e6), (int) (log12 * 1e6));
p14=new GeoPoint( (int) (t6* 1e6), (int) (log11 * 1e6));
p15=new GeoPoint( (int) ((t6+t1)/2* 1e6), (int) (log3 * 1e6));
p15=new GeoPoint( (int) (t3* 1e6), (int) (log11 * 1e6));
p16=new GeoPoint( (int) (lat15* 1e6), (int) (log15 * 1e6));
p17=new GeoPoint( (int) (lat13* 1e6), (int) (log13 * 1e6));
p18=new GeoPoint( (int) (lat9* 1e6), (int) (log9 * 1e6));
p19=new GeoPoint( (int) (lat10* 1e6), (int) (log10 * 1e6));
p20=new GeoPoint( (int) (lat11* 1e6), (int) (log11 * 1e6));
p21=new GeoPoint( (int) (lat12* 1e6), (int) (log12 * 1e6));
mapOverlays = mapView.getOverlays();
drawable = this.getResources().getDrawable(R.drawable.wit);
drawable2 = this.getResources().getDrawable(R.drawable.ballon);
itemizedOverlay = new HelloItemizedOverlay(drawable, this);
itemizedOverlay2 = new HelloItemizedOverlay(drawable2, this);
OverlayItem overlayitem = new OverlayItem(p, "Cairo", " over1");
OverlayItem over2 = new OverlayItem(p2, "ulm", "over2");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
itemizedOverlay2.addOverlay(over2);
mapOverlays.add(itemizedOverlay2);
mc.setZoom(17);
}
public void Location(){
LocationManager myLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener1 = new MyLocationListener();
LocationManager mlocManager1 = null;
mlocManager1.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
0, mlocListener1);
// Get the current location in start-up
GeoPoint initGeoPoint = new GeoPoint((int)(myLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)
.getLatitude()*1000000),(int)(myLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER).getLongitude()*1000000));
mc.animateTo(initGeoPoint);
mc.setZoom(16);
drawable21 = this.getResources().getDrawable(R.drawable.ggg);
itemizedOverlay21 = new HelloItemizedOverlay(drawable21,this);
OverlayItem over21 = new OverlayItem(initGeoPoint, "offff", "over21");
itemizedOverlay21.addOverlay(over21);
mapOverlays.add(itemizedOverlay21);
}
/* Class My Location Listener */
public class MyLocationListener implements LocationListener
{
#Override
public void onLocationChanged(Location loc)
{
GeoPoint point = new GeoPoint((int) (loc.getLatitude() * 1E6),
(int) (loc.getLongitude() * 1E6));
String Text = "My current location is: " +
"Latitud =" + loc.getLatitude()+
"Longitud =" +loc.getLongitude() ;
Toast.makeText(getApplicationContext(),
Text,
Toast.LENGTH_SHORT).show();
mc.animateTo(point);
}
private Resources getResources() {
// TODO Auto-generated method stub
return null;
}
public void onProviderDisabled(String provider)
{
Toast.makeText(getApplicationContext(),
"Gps Disabled",
Toast.LENGTH_SHORT).show();
}
public void onProviderEnabled(String provider)
{
Toast.makeText(getApplicationContext(),
"Gps Enabled",
Toast.LENGTH_SHORT).show();
}
public void onStatusChanged(String provider, int status, Bundle extras)
{
}
protected boolean isRouteDisplayed() {
return false;
}
}/* End of Class MyLocationListener */
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
You have a NullPointerException on line 92 of yarab.java, in your onCreate() method. Based on the comment by #dmon, my guess is that you are loading the wrong layout and therefore your attempt to retrieve your MapView fails. However, that is just a guess, since you did not tell us what line 92 of yarab.java actually is.
what is The command for removing specific overlay item ?
if here is my code of the added items
public void addOverLays(){
String [] coordinates = {"30.084262490272522","31.33625864982605" ,"30.084123015403748", "51.5002" , "-0.1262","31.337149143218994"};
double lat = 30.084262490272522, lat2 = 51.5002,lat3=29.987091422080994;
double log = 31.33625864982605, log2 = -0.1262,log3=31.43909454345703;
p = new GeoPoint((int) (lat * 1E6), (int) (log * 1E6));
p2 = new GeoPoint( (int) (lat2 * 1e6), (int) (log2 * 1e6));
p3=new GeoPoint( (int) (lat3 * 1e6), (int) (log3 * 1e6));
mapOverlays = mapView.getOverlays();
drawable = this.getResources().getDrawable(R.drawable.ballon);
drawable2 = this.getResources().getDrawable(R.drawable.ballon);
drawable3 = this.getResources().getDrawable(R.drawable.ballon);
itemizedOverlay = new HelloItemizedOverlay(drawable,this);
itemizedOverlay2 = new HelloItemizedOverlay(drawable2,this);
itemizedOverlay3 = new HelloItemizedOverlay(drawable3,this);
OverlayItem overlayitem = new OverlayItem(p, "Cairo", " over1");
OverlayItem over2 = new OverlayItem(p2, "ulm", "over2");
OverlayItem over3 = new OverlayItem(p3, "offff", "over3");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
itemizedOverlay2.addOverlay(over2);
mapOverlays.add(itemizedOverlay2);
itemizedOverlay3.addOverlay(over3);
mapOverlays.add(itemizedOverlay3);
Replace add() with remove():
mapView.getOverlays().remove(<putYourOverlayHere>);
mapView.invalidate();
how can i make a loop for my overlay items android !! and what if i want to remove one of them by using mapView.getOverlays().remove(p); !! its doesn't work why ?? here is the code
enter code here
public void addOverLays(){
String [] coordinates = {"31.216487288475037","29.932637214660645" ,"30.084123015403748", "51.5002" , "-0.1262","31.337149143218994"};
double lat = 30.084686279296875,lat2 = 51.5002,lat3=29.987091422080994;
double log = 31.33642494678493, log2 = -0.1262,log3=31.43909454345703;
p = new GeoPoint((int) (lat * 1E6), (int) (log * 1E6));
p2 = new GeoPoint( (int) (lat2 * 1e6), (int) (log2 * 1e6));
p3=new GeoPoint( (int) (lat3 * 1e6), (int) (log3 * 1e6));
mapOverlays = mapView.getOverlays();
drawable = this.getResources().getDrawable(R.drawable.pushpin);
drawable2 = this.getResources().getDrawable(R.drawable.ballon);
drawable3 = this.getResources().getDrawable(R.drawable.ballon);
itemizedOverlay = new HelloItemizedOverlay(drawable,this);
itemizedOverlay2 = new HelloItemizedOverlay(drawable2,this);
itemizedOverlay3 = new HelloItemizedOverlay(drawable3,this);
OverlayItem overlayitem = new OverlayItem(p, "Cairo", " over1");
OverlayItem over2 = new OverlayItem(p2, "ulm", "over2");
OverlayItem over3 = new OverlayItem(p3, "offff", "over3");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
itemizedOverlay2.addOverlay(over2);
mapOverlays.add(itemizedOverlay2);
itemizedOverlay3.addOverlay(over3);
mapOverlays.add(itemizedOverlay3);
mc.setZoom(17);
mc.animateTo(p);
}
Adding overlays does work in your code - if you mean you don't see any changes, then you have to call MapView.invalidate() to have it re-draw itself with the newly added overlays. The same is true when you remove an overlay.