下面一段mapactivity代码,可正常显示地图,如下public class Map4Activity extends MapActivity{
private MapView mMapView;
private MapController mMapController;
private GeoPoint mGeoPoint;
private GeoPoint mGeoPoint2;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setStreetView(false); //取得MapController对象(控制MapView)
mMapController = mMapView.getController();
mMapView.setEnabled(true);
mMapView.setClickable(true); //设置地图支持缩放
mMapView.setBuiltInZoomControls(true); //设置起点为成都
mGeoPoint = new GeoPoint((int) (28.68 * 1000000), (int) (115.89 * 1000000)); //定位到成都
mMapController.animateTo(mGeoPoint); //设置倍数(1-21)
mMapController.setZoom(15); //添加Overlay,用于显示标注信息
MyLocationOverlay myLocationOverlay = new MyLocationOverlay();
List<Overlay> list = mMapView.getOverlays();
list.add(myLocationOverlay);
}
protected boolean isRouteDisplayed()
{
return false;
}
class MyLocationOverlay extends Overlay {
public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when)
{
super.draw(canvas, mapView, shadow);
Paint paint = new Paint();
Point myScreenCoords = new Point();
mapView.getProjection().toPixels(mGeoPoint, myScreenCoords);
paint.setStrokeWidth(1);
paint.setARGB(255, 255, 0, 0);
paint.setStyle(Paint.Style.STROKE);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.map_point);
String xx="-1655";
String yy="646";
Float x1;
x1=Float.parseFloat(xx);
Float y1;
y1=Float.parseFloat(yy);
canvas.drawBitmap(bmp, myScreenCoords.x+50, myScreenCoords.y+50, paint);
canvas.drawText("天府广场", myScreenCoords.x+50, myScreenCoords.y+50, paint);
System.out.println("x"+myScreenCoords.x);
return true;
}
}
}现需:如何得到此手机的x y坐标呢,thanks
private MapView mMapView;
private MapController mMapController;
private GeoPoint mGeoPoint;
private GeoPoint mGeoPoint2;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setStreetView(false); //取得MapController对象(控制MapView)
mMapController = mMapView.getController();
mMapView.setEnabled(true);
mMapView.setClickable(true); //设置地图支持缩放
mMapView.setBuiltInZoomControls(true); //设置起点为成都
mGeoPoint = new GeoPoint((int) (28.68 * 1000000), (int) (115.89 * 1000000)); //定位到成都
mMapController.animateTo(mGeoPoint); //设置倍数(1-21)
mMapController.setZoom(15); //添加Overlay,用于显示标注信息
MyLocationOverlay myLocationOverlay = new MyLocationOverlay();
List<Overlay> list = mMapView.getOverlays();
list.add(myLocationOverlay);
}
protected boolean isRouteDisplayed()
{
return false;
}
class MyLocationOverlay extends Overlay {
public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when)
{
super.draw(canvas, mapView, shadow);
Paint paint = new Paint();
Point myScreenCoords = new Point();
mapView.getProjection().toPixels(mGeoPoint, myScreenCoords);
paint.setStrokeWidth(1);
paint.setARGB(255, 255, 0, 0);
paint.setStyle(Paint.Style.STROKE);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.map_point);
String xx="-1655";
String yy="646";
Float x1;
x1=Float.parseFloat(xx);
Float y1;
y1=Float.parseFloat(yy);
canvas.drawBitmap(bmp, myScreenCoords.x+50, myScreenCoords.y+50, paint);
canvas.drawText("天府广场", myScreenCoords.x+50, myScreenCoords.y+50, paint);
System.out.println("x"+myScreenCoords.x);
return true;
}
}
}现需:如何得到此手机的x y坐标呢,thanks
根据你贴出来的,
mGeoPoint = new GeoPoint((int) (28.68 * 1000000), (int) (115.89 * 1000000)); //定位到成都
已经帮你定位到指定的地点了,不知道你想获得的是什么坐标。如果你想地位到自己当前的位置,需要用LocationManager去获取。
如果你想实现点击地图就显示坐标的话,这点代码是不行的,必须要自己画图层(Overlay)上去。
你可以这样去理解,本来的这个mapView是不会相应你的点击事件的,所以你需要在地图表面画个透明的图层,而这个图层可以相应你的点击,拖拉事件。甚至可以画自己的小图标。这个就是一般的地图软件实现的功能。
我在XML中添加控件后出现Failed to find style 'mapViewStyle' in current theme
是什么原因,望指教
我用这个得不到坐标啊