在我的地图视图中,在SingleTapUp中使用了地理定位。每当使用mapview的缩放控件时,也会调用singleTapUp。任何克服这种情况的建议。
我的主方法中的代码
public static TextView info;
private MapController mapController;
private MapView mapView;
public LocationManager orgManager;
private MyOverlays itemizedoverlay, blackmarker;
public boolean gps_enabled = false;
public boolean network_enabled = false;
public Criteria c;
public String bestProvider;
public double orginLongitude, orginLatitude, destLongtitude, destLatitude,
currLatitude, currLongtitude, lat, lon;
public boolean isLongPress= false, GPSfix = false;
Location originLocation = new Location("source");
Location currLocation = new Location("current");
Location destinationLocation = new Location("destination");
Location fixlocation= new Location("fix");
NotificationManager nm;
Vibrator v;
MediaPlayer mp = new MediaPlayer();
private TextToSpeech myTTS;
private int MY_DATA_CHECK_CODE = 0;
private List<Overlay> mapOverlays;
private Projection projection;
GestureDetector gestureScanner;
long lastGesture = System.currentTimeMillis();
GeoPoint markerPoint = null;
private int count = 0;
MyLocationOverlay mo;
public GeoPoint source;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_layout);
info = (TextView) findViewById(R.id.infopane);
mapView = (MapView) findViewById(R.id.mapView);
//Button myloc = (Button)findViewById(R.id.myloc);
info.setText("Please Tap on the Map");
orgManager = (LocationManager) this
.getSystemService(Context.LOCATION_SERVICE);
mapView.setBuiltInZoomControls(true);
mapView.setSatellite(true);
markerPoint = null;
mapController = mapView.getController();
mapController.setZoom(16); // Zoom 1 is world view
mapView.invalidate();
mo = new MyLocationOverlay(MapClass.this, mapView);
mapView.getOverlays().add(mo);
mapOverlays = mapView.getOverlays();
projection = mapView.getProjection();
Drawable drawable = this.getResources()
.getDrawable(R.drawable.mark_red);
Drawable black_marker = this.getResources().getDrawable(
R.drawable.marker_black);
itemizedoverlay = new MyOverlays(drawable);
blackmarker = new MyOverlays(black_marker);
try {
gps_enabled = orgManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
Log.i("success", "Gps:" + String.valueOf(gps_enabled)+ "N/w:" + String.valueOf(network_enabled) );
} catch (Exception ex) {
Log.i("sample", "sample");
}
if (!gps_enabled) {
Log.i("failure", "Gps:" + String.valueOf(gps_enabled)+ "N/W:" + String.valueOf(network_enabled) );
final AlertDialog.Builder builder = new AlertDialog.Builder(MapClass.this);
builder.setTitle("Attention!");
builder.setMessage("Sorry, location is not determined. Please open app after enabling GPS & wireless networks").setCancelable(false).setPositiveButton("OK", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
startActivity(new Intent(
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
finish();
}
});
AlertDialog alert = builder.create();
alert.show();
}
if(gps_enabled){
orgManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
fixlocation = orgManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
Log.i("fix", String.valueOf(fixlocation.getLatitude() + fixlocation.getLongitude()));
if (fixlocation!=null){
originLocation.setLatitude(fixlocation.getLatitude());
originLocation.setLongitude(fixlocation.getLongitude());
Log.i("origin fix", String.valueOf(originLocation.getLatitude() + originLocation.getLongitude()));
GPSfix = true;
}else Toast.makeText(MapClass.this, "", Toast.LENGTH_SHORT).show();
}
if (GPSfix) {
// double a = originLocation.getLatitude();
// double b = originLocation.getLongitude();
source = new GeoPoint(
(int) ((fixlocation.getLatitude()) * 1E6),
(int) ((fixlocation.getLongitude()) * 1E6));
mapController.animateTo(source);
mapView.getMapCenter();
createMarker();
Toast.makeText( MapClass.this," Source GPS Values Latitude: "
+ fixlocation.getLatitude() + " Longitude: "
+ fixlocation.getLongitude(), Toast.LENGTH_SHORT).show();
}
else Toast.makeText(MapClass.this, "Wait for GPS", Toast.LENGTH_SHORT).show();
gestureScanner = new GestureDetector(this, this);
}
手势扫描器方法中的代码。
>
昂隆出版社
@Override
public void onLongPress(final MotionEvent e) {
// TODO Auto-generated method stuMapClass Toast.makeText(MapClass.this,
// "LongPress", Toast.LENGTH_SHORT)
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MapClass.this);
// Setting Dialog Title
alertDialog.setTitle("Alert!!");
// Setting Dialog Message
alertDialog.setMessage("Do you want to select this as destination");
// Setting Positive "Yes" Button
alertDialog.setPositiveButton("YES",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Write your code here to execute after dialog
String add = "";
GeoPoint geopoint = mapView.getProjection().fromPixels(
(int) e.getX(), (int) e.getY());
// latitude
lat = geopoint.getLatitudeE6() / 1E6;
// longitude
lon = geopoint.getLongitudeE6() / 1E6;
Geocoder geoCoder = new Geocoder(getBaseContext(),
Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(
geopoint.getLatitudeE6() / 1E6,
geopoint.getLongitudeE6() / 1E6, 1);
if (addresses.size() > 0) {
for (int i = 0; i < addresses.get(0)
.getMaxAddressLineIndex(); i++)
add += addresses.get(0).getAddressLine(i)
+ "\n";
}
Toast.makeText(getBaseContext(), add,
Toast.LENGTH_SHORT).show();
} catch (IOException ioe) {
ioe.printStackTrace();
}
mapOverlays.add(new MyOverlay((originLocation
.getLatitude()),
(originLocation.getLongitude()), lat, lon));
destinationLocation.setLatitude(lat);
destinationLocation.setLongitude(lon);
String distance = Float.toString((originLocation
.distanceTo(destinationLocation) / 1000));
createblack();
count++;
Toast.makeText(getBaseContext(), distance + "kms",
Toast.LENGTH_SHORT).show();
info.setText("Selected destination is " + "\n" + add
+ "\n" + " The journey distance is " + distance
+ " Kms ");
mapView.postInvalidate();
isLongPress = true;
mapController.animateTo(source);
mapView.getMapCenter();
}
private void createblack() {
// TODO Auto-generated method stub
GeoPoint p = new GeoPoint((int) (lat * 1E6),
(int) (lon * 1E6));
OverlayItem overlayitem = new OverlayItem(p,
"Destination", "");
blackmarker.addOverlay(overlayitem);
mapView.getOverlays().add(blackmarker);
}
});
// Setting Negative "NO" Button
alertDialog.setNegativeButton("NO",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Write your code here to execute after dialog
Toast.makeText(getApplicationContext(),
"You clicked on NO", Toast.LENGTH_SHORT).show();
dialog.cancel();
}
});
// Showing Alert Message
alertDialog.show();
}
@凌驾
公共布尔onSingleTapUp(MotionEvent arg0){//TODO自动生成的方法存根
Log.i("SingleTap", arg0.toString());
GeoPoint geopoint = mapView.getProjection().fromPixels(
(int) arg0.getX(), (int) arg0.getY());
Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(
geopoint.getLatitudeE6() / 1E6,
geopoint.getLongitudeE6() / 1E6, 1);
String add = "";
if (addresses.size() > 0) {
for (int i = 0; i < addresses.get(0).getMaxAddressLineIndex(); i++)
add += addresses.get(0).getAddressLine(i) + "\n";
}
if (count == 0) {
info.setText("The location you have selected is" + "\n" + add
+ "\n" + "To confirm it longpress the location");
} else
Toast.makeText(getBaseContext(), add, Toast.LENGTH_SHORT)
.show();
} catch (IOException ioe2) {
ioe2.printStackTrace();
}
return true;
}
此外,还使用了覆盖类来放置标记。。
调试代码有点困难,因为缺少重要部分,但我建议看看类似的StackOverflow问题的以下答案:
https://stackoverflow.com/a/2990749/376016
在MapView上识别手势的建议解决方案是创建一个只处理触摸事件的自定义覆盖图,并将其作为第一个覆盖图插入。使用这种方法,我能够创建一个小的测试应用程序,它使用了您的大部分代码,并且正确地忽略了MapView上的缩放手势。
问题内容: 经过一番工作后,我的路线申请工作正常。我唯一想添加的就是双击放大功能,但我不知道如何操作。 你能给我一个提示吗? 问题答案: 实现GestureListener来接收doubleTap事件。
我有一个按钮,应该在最右边的角落,所以我使用了CSS,在100%缩放,它工作良好,但当我给出75%缩小,它显示的按钮在中间,我试着给出//,但没有工作。 有人能帮帮我吗。 null null 放大和缩小时的图像 100%放大 67%放大
我正试着从后面取回碎片。它正在被检索,但问题是在按下后退按钮时,当前片段的oncreate视图和后续lifecyce方法也会被调用。下面是我将片段放入backbackback的代码: 以下是片段的代码:
我正在尝试调整嵌入到div容器中的svg的大小和缩放。我的目标是通过道具改变te svg作为一个React组件。您可以在这里查看代码沙箱。 我使用viewbox和矩阵变换使svg圆圈保持其在窗口调整大小上的位置。我可以在鼠标滚轮上相应地缩放圆圈。对于缩放,我在window resize事件上设置组件状态中父容器的宽度和高度。 但是当我在改变窗口大小之前缩放时,圆圈就不在它的位置了。 你知道如何使我
我有一个小部件,我想缩放(像素完美)。根据设备的显示宽度,的大小应该增加或减少。我尝试了小部件来更改的大小。这工作得很好,但是小部件的大小永远不会改变。它总是与的原始大小相匹配(不缩放)。有没有办法强制总是采用其子级的大小?或者有替代方法吗? 您可以在此处找到显示当前和所需情况的图像 编辑:小部件及其子部件应均匀收缩/增长。它们之间的比率不应改变。 这是我目前尝试的代码
问题内容: 我有这个代码 它的工作原理,但不是我所期望的。声音会播放,但仅在我每次按下按钮时播放。我的主意是 当我按下按钮时,声音会播放,当我停止动作(手指在按钮之外)时,音乐会暂停。 有什么想法吗? 谢谢 问题答案: 这应该可以工作(我认为您的开关柜出了点问题):