Android 在openstreetmap中更改位置并单击放置标记
我是新打开街道地图。我想把标记放在我点击的地图上。我还想删除上一个标记。请帮帮我。 提前谢谢。这是我的密码Android 在openstreetmap中更改位置并单击放置标记,android,openstreetmap,marker,Android,Openstreetmap,Marker,我是新打开街道地图。我想把标记放在我点击的地图上。我还想删除上一个标记。请帮帮我。 提前谢谢。这是我的密码 Overlay touchOverlay = new Overlay(this) { ItemizedIconOverlay<OverlayItem> anotherItemizedIconOverlay = null; @Override protected void draw(Canvas arg0, MapView arg1, boolean a
Overlay touchOverlay = new Overlay(this) {
ItemizedIconOverlay<OverlayItem> anotherItemizedIconOverlay = null;
@Override
protected void draw(Canvas arg0, MapView arg1, boolean arg2) {
}
@Override
public boolean onSingleTapConfirmed(final MotionEvent e,
final MapView mapView) {
Projection proj = mapView.getProjection();
GeoPoint loc = (GeoPoint) proj.fromPixels((int) e.getX(),
(int) e.getY());
String longitude = Double
.toString(((double) loc.getLongitudeE6()) / 1000000);
String latitude = Double
.toString(((double) loc.getLatitudeE6()) / 1000000);
ArrayList<OverlayItem> overlayArray = new ArrayList<OverlayItem>();
OverlayItem mapItem = new OverlayItem("", "", new GeoPoint(
(((double) loc.getLatitudeE6()) / 1000000),
(((double) loc.getLongitudeE6()) / 1000000)));
Drawable marker = null;
mapItem.setMarker(marker);
overlayArray.add(mapItem);
if (anotherItemizedIconOverlay == null) {
anotherItemizedIconOverlay = new ItemizedIconOverlay<OverlayItem>(
getApplicationContext(), overlayArray, null);
mapView.getOverlays().add(anotherItemizedIconOverlay);
mapView.invalidate();
} else {
mapView.getOverlays().remove(anotherItemizedIconOverlay);
mapView.invalidate();
anotherItemizedIconOverlay = new ItemizedIconOverlay<OverlayItem>(
getApplicationContext(), overlayArray, null);
mapView.getOverlays().add(anotherItemizedIconOverlay);
}
return true;
}
};
Overlay touchOverlay=新覆盖(此){
itemizedictionoverlay另一个itemizedictionoverlay=null;
@凌驾
受保护的空绘图(画布arg0、地图视图arg1、布尔值arg2){
}
@凌驾
公共布尔值OnSingleTapConfiged(最终运动事件e,
最终地图视图(地图视图){
Projection proj=mapView.getProjection();
GeoPoint loc=(GeoPoint)proj.fromPixels((int)e.getX(),
(int)e.getY();
字符串经度=双精度
.toString(((双)loc.getLongitudeE6())/1000000);
字符串纬度=双
.toString(((双)loc.getLatitudeE6())/1000000);
ArrayList overlayArray=新的ArrayList();
OverlayItem mapItem=新的OverlayItem(“,”,新的地质点(
((双精度)loc.getLatitudeE6())/1000000),
((双)loc.getLongitudeE6())/1000000));
可绘制标记=null;
mapItem.setMarker(marker);
overlayArray.add(mapItem);
if(anotheritemizedictionoverlay==null){
anotheritemizedictionoverlay=新的itemizedictionoverlay(
getApplicationContext(),overlayArray,null);
mapView.getOverlays().add(AnotheritemizedEdiconOverlay);
mapView.invalidate();
}否则{
mapView.getOverlays().remove(另一个ItemizedEdiconOverlay);
mapView.invalidate();
anotheritemizedictionoverlay=新的itemizedictionoverlay(
getApplicationContext(),overlayArray,null);
mapView.getOverlays().add(AnotheritemizedEdiconOverlay);
}
返回true;
}
};
我终于找到了这个问题的解决方案。这是我的答案
@Override
public boolean onSingleTapConfirmed(MotionEvent e, MapView mapView) {
Projection proj = mapView.getProjection();
p = (GeoPoint) proj.fromPixels((int) e.getX(), (int) e.getY());
proj = mapView.getProjection();
loc = (GeoPoint) proj.fromPixels((int) e.getX(), (int) e.getY());
String longitude = Double
.toString(((double) loc.getLongitudeE6()) / 1000000);
String latitude = Double
.toString(((double) loc.getLatitudeE6()) / 1000000);
Toast toast = Toast.makeText(getApplicationContext(),
"Longitude: "
+ longitude + " Latitude: " + latitude, Toast.LENGTH_SHORT);
toast.show();
return true;
}
private void addLocation(double lat, double lng) {
// ---Add a location marker---
p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
Drawable marker = getResources().getDrawable(
android.R.drawable.star_big_on);
int markerWidth = marker.getIntrinsicWidth();
int markerHeight = marker.getIntrinsicHeight();
marker.setBounds(0, markerHeight, markerWidth, 0);
ResourceProxy resourceProxy = new DefaultResourceProxyImpl(
getApplicationContext());
myItemizedOverlay = new MyItemizedOverlay(marker, resourceProxy);
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(myItemizedOverlay);
mapView.invalidate();
}
@覆盖
公共布尔值OnSingleTapConfiged(MotionEvent e,MapView MapView){
Projection proj=mapView.getProjection();
p=(地理点)项目从像素((int)e.getX(),(int)e.getY());
proj=mapView.getProjection();
loc=(地理点)proj.fromPixels((int)e.getX(),(int)e.getY());
字符串经度=双精度
.toString(((双)loc.getLongitudeE6())/1000000);
字符串纬度=双
.toString(((双)loc.getLatitudeE6())/1000000);
Toast Toast=Toast.makeText(getApplicationContext(),
“经度:”
+经度+“纬度:”+纬度,土司。长度(短);
toast.show();
返回true;
}
专用位置(双lat、双lng){
//---添加位置标记---
p=新地质点((内部)(纬度*1E6),(内部)(液化天然气*1E6));
可绘制标记=getResources().getDrawable(
android.R.drawable.star\u big\u on);
int-markerWidth=marker.getIntrinsicWidth();
int-markerHeight=marker.getIntrinsicHeight();
标记.立根(0,标记高度,标记宽度,0);
ResourceProxy ResourceProxy=新的DefaultResourceProxyImpl(
getApplicationContext());
myItemizedOverlay=新的myItemizedOverlay(标记,resourceProxy);
List ListoForLays=mapView.getOverlays();
listOfOverlays.clear();
添加(myItemizedOverlay);
mapView.invalidate();
}