android google地图得到 此手机的x y坐标,在线等

zgycsmb zgycsmb 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
下面一段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
...全文

相关推荐

评论 7
收藏 已收藏
分享
返回顶部
zgycsmb
Android 80,489 成员 91,375 内容