พอดีทำ app ที่ปักหมุดลงไปในแผนที่ครับ แล้ว มีข้อมูล lati,long อยู่ชุดนึง เก็บเป็น array ผมต้องการปักหมุด ที่ lati,long ทุกข้อมูลที่มีอยู่ใน array แต่ผมไม่รู้ว่าจะทำยังไงให้มันเป็น dynamic ครับ ผู้รู้แนะนำหน่อยน่ะครับ
———————————————————————————-
import java.util.List;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
public class mapActivity extends MapActivity {
private MapView map=null;
private MyLocationOverlay me=null;
private ImageView im;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setLayout();
setEvent();
}
private void setLayout() {
// TODO Auto-generated method stub
map=(MapView)findViewById(R.id.map);
map.getController().setCenter(getPoint(13.727556,100.529986));
map.setBuiltInZoomControls(true);
me=new MyLocationOverlay(this, map);
map.getOverlays().add(me);
List mapOverlays = map.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.pin);
ItemizedOverlayMaps itemizedoverlay = new ItemizedOverlayMaps(drawable,this);
GeoPoint point = new GeoPoint((int)(13.727556 * 1E6),(int)(100.529986 * 1E6));
OverlayItem overlayitem = new OverlayItem(point, “ประเทศไทย”,”อาคารบุญมิตร”);
GeoPoint point2 = new GeoPoint((int)(13.627754 * 1E6),(int)(100.530049 * 1E6));
OverlayItem overlayitem2 = new OverlayItem(point2, “Namashkaar!”, “I’m in Hyderabad, India!”);
itemizedoverlay.addOverlay(overlayitem);
itemizedoverlay.addOverlay(overlayitem2);
mapOverlays.add(itemizedoverlay);
}
private void setEvent() {
// TODO Auto-generated method stub
im = (ImageView)findViewById(R.id.image1);
im.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.v(“newnhon”, “click”);
Intent i = new Intent(mapActivity.this,IMactivity.class);
startActivity(i);
}
});
}
@Override
public void onResume() {
super.onResume();
me.enableCompass();
}
@Override
public void onPause() {
super.onPause();
me.disableCompass();
}
@Override
protected boolean isRouteDisplayed() {
return(false);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_S) {
map.setSatellite(!map.isSatellite());
return(true);
}
else if (keyCode == KeyEvent.KEYCODE_Z) {
map.displayZoomControls(true);
return(true);
}
return(super.onKeyDown(keyCode, event));
}
private GeoPoint getPoint(double lat, double lon) {
return(new GeoPoint((int)(lat*1000000.0),
(int)(lon*1000000.0)));
}
}
————————————————————————————————-
package com.googleMap;
import java.util.ArrayList;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;
public class ItemizedOverlayMaps extends ItemizedOverlay{
private ArrayList mOverlays = new ArrayList();
private Context mContext;
public ItemizedOverlayMaps(Drawable defaultMarker, Context context){
super(boundCenterBottom(defaultMarker));
mContext = context;
}
public void addOverlay(OverlayItem overlay){
mOverlays.add(overlay);
populate();
}
@Override
protected OverlayItem createItem(int i){
return mOverlays.get(i);
}
@Override
public int size(){
return mOverlays.size();
}
@Override
protected boolean onTap(int index){
OverlayItem item = mOverlays.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
return true;
}
}