我的问题是我在特定位置使用PushPin显示谷歌地图但在我的应用程序中,如果用户可以点击图钉,位置名称显示在吐司或文本视图中,但我不知道如何做到这一点?
请帮助我。
以下是我的代码: -
Map_Activity.java: -
public class Map_Activity extends MapActivity {
String mArea;
MapView mapView;
MapController mc;
GeoPoint p;
String[] mLongitude,mLatitude,mAreaArray;
double lat,lng;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.google_map_screen);
Bundle bdl=getIntent().getExtras();
mArea= bdl.getString("Area Name");
mAreaArray=getResources().getStringArray(R.array.PlaceName);
mLongitude=getResources().getStringArray(R.array.Longitude);
mLatitude=getResources().getStringArray(R.array.Latitude);
for(int i=0;i<mAreaArray.length;i++){
if(mArea.equals(mAreaArray[i])){
lat=Float.valueOf(mLatitude[i]);
lng=Float.valueOf(mLongitude[i]);
}
}
mapView = (MapView) findViewById(R.id.googlemap);
LinearLayout zoomLayout = (LinearLayout) findViewById(R.id.zoom);
@SuppressWarnings("deprecation")
View zoomView = mapView.getZoomControls();
zoomLayout.addView(zoomView, new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
mapView.displayZoomControls(true);
mc = mapView.getController();
p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
mc.animateTo(p);
mc.setZoom(17);
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
mapView.invalidate();
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
MapController mc = mapView.getController();
switch (keyCode) {
case KeyEvent.KEYCODE_3:
mc.zoomIn();
break;
case KeyEvent.KEYCODE_1:
mc.zoomOut();
break;
}
return super.onKeyDown(keyCode, event);
}
class MapOverlay extends com.google.android.maps.Overlay {
@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
long when) {
super.draw(canvas, mapView, shadow);
// ---translate the GeoPoint to screen pixels---
Point screenPts = new Point();
mapView.getProjection().toPixels(p, screenPts);
// ---add the marker---
Bitmap bmp = BitmapFactory.decodeResource(getResources(),
R.drawable.pushpin);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y - 50, null);
return true;
}
@Override
public boolean onTap(GeoPoint p, MapView mapView) {
// TODO Auto-generated method stub
Toast.makeText(Google_Map_Activity.this, "Sorry Don't Click", Toast.LENGTH_SHORT).show();
return super.onTap(p, mapView);
}
}
}
答案 0 :(得分:1)
请点击以下链接:
http://developer.android.com/guide/tutorials/views/hello-mapview.html
http://www.vogella.de/articles/AndroidLocationAPI/article.html
答案 1 :(得分:0)
按照下面的链接进行操作。这提供了所有步骤的详细说明。
http://mobiforge.com/developing/story/using-google-maps-android