// 1E6)
// 按钮添加监听器
button_location = (Button) findViewById(R.id.location);
longitude = (EditText) findViewById(R.id.longitude);
latidute = (EditText) findViewById(R.id.latitude);
locationListener = new OnClickListener() {
public void onClick(View e) {
if (e.equals(button_location)) {
// 得到文本输入框的中经纬 度坐标值
String latStr = longitude.getText().toString();
// 将得到的字符串转成数值
double lat = Integer.parseInt(latStr);
String lngStr = latidute.getText().toString();
double lng = Integer.parseInt(lngStr);
//转成经纬度坐标
lat=lat*1E6;
lng=lng*1E6;
// 用给定的经纬度构造一个GeoPoint,单位是微度(度*1E6)
point = new GeoPoint((int) (lat), (int) (lng));
mMapController.setCenter(point); // 设置地图中心点
mMapController.setZoom(12); // 设置地图zoom 级别
// 添加地图覆盖物
//MyLocationOverlay(this, mMapView);
mylocTest.enableMyLocation(); // 判断是否发现位置提供者
mylocTest.enableCompass(); // 打开指南针
mMapView.getOverlays().add(mylocTest);// 添加定位覆盖物
}
}
};
// 按钮添加监听器
button_location.setOnClickListener(locationListener);
mMapController.setCenter(point); // 设置地图中心点
mMapController.setZoom(12); // 设置地图zoom 级别
// 添加地图覆盖物
mylocTest = new MyLocationOverlay(this, mMapView);
mylocTest.enableMyLocation(); // 判断是否发现位置提供者
mylocTest.enableCompass(); // 打开指南针
mMapView.getOverlays().add(mylocTest);// 添加定位覆盖物
}
//另外一个添加界面覆盖物的类:
public class MyLocationOverlayProxy extends com.amap.mapapi.map.MyLocationOverlay{
private Location mLocation;
protected final Paint mPaint = new Paint();
protected final Paint mCirclePaint = new Paint();
private Bitmap gps_marker=null;
private Point mMapCoords = new Point();
private final float gps_marker_CENTER_X;
private final float gps_marker_CENTER_Y;
private final LinkedListRunnable mRunOnFirstFix = new LinkedListRunnable();
public MyLocationOverlayProxy(amap amap, MapView mMapView) {
super(amap, mMapView);
gps_marker = ((BitmapDrawable) amap.getResources().getDrawable(
R.drawable.marker_gpsvalid)).getBitmap();
gps_marker_CENTER_X = gps_marker.getWidth() / 2 - 0.5f;
gps_marker_CENTER_Y= gps_marker.getHeight() / 2 - 0.5f;
}
public boolean runOnFirstFix(final Runnable runnable) {
if (mLocation != null) {
new Thread(runnable).start();
return true;
} else {
mRunOnFirstFix.addLast(runnable);
return false;
}
}
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
mLocation = location;
for(final Runnable runnable : mRunOnFirstFix) {
new Thread(runnable).start();
}
mRunOnFirstFix.clear();
super.onLocationChanged(location);
}
protected void drawMyLocation(Canvas canvas,MapView mapView, final Location mLocation,
GeoPoint point, long time) {
Projection pj=mapView.getProjection();
if (mLocation != null) {
mMapCoords=pj.toPixels(point, null);
final float radius = pj.metersToEquatorPixels(mLocation.getAccuracy());
this.mCirclePaint.setAntiAlias(true);
this.mCirclePaint.setARGB(35, 131, 182, 222);
this.mCirclePaint.setAlpha(50);
this.mCirclePaint.setStyle(Style.FILL);
canvas.drawCircle(mMapCoords.x, mMapCoords.y, radius, this.mCirclePaint);
this.mCirclePaint.setARGB(225, 131, 182, 222);
this.mCirclePaint.setAlpha(150);
this.mCirclePaint.setStyle(Style.STROKE);
canvas.drawCircle(mMapCoords.x, mMapCoords.y, radius, this.mCirclePaint);
canvas.drawBitmap(gps_marker, mMapCoords.x-gps_marker_CENTER_X, mMapCoords.y-gps_marker_CENTER_Y, this.mPaint);
推荐阅读
- 如何理解营销查询,营销的查询
- 怎么知道chatgpt是真是假的简单介绍
- 射击养成类手机游戏推荐,射击类游戏手游排行
- mysql链接怎么填写 mysql的连接方式有哪些
- jquery怎么改变标签i的颜色,jq修改a标签的href
- 如何推广一个新品类,怎么推广店里的新品
- 泾县招聘直播运营主管,高薪招聘直播运营
- 日志时间段linux命令 linux日志一般放在哪个根目录
- postgresql异地备份,sql数据库异地备份工具