【发布时间】:2014-08-11 04:01:17
【问题描述】:
当用户单击地图上的某个位置时,会打开一个对话框警报框,提示用户是否要添加标记,如果是,则添加标记。我正在尝试编写另一种方法,如果用户通过此标记,则标记会改变颜色。
我在编写其中的标记检查部分时遇到问题。
我的代码:
public void onMapClick(){
map.setOnMapClickListener(new OnMapClickListener() {
@Override
public void onMapClick(LatLng latlng) {
dialogBox(latlng);
}
});
}
private void dialogBox(final LatLng latlng) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MapActivity.this);
alertDialogBuilder.setTitle("Add Marker");
alertDialogBuilder
.setMessage("Add marker?").setCancelable(false)
.setPositiveButton("yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
double dialogLat = latlng.latitude;
double dialogLng = latlng.longitude;
dialogMarker = map.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN))
.position(latlng).title("dialog maker"));
//if location hit, places marker around that area
hitLocation(dialogLat,dialogLng);
}
})
.setNegativeButton("no", new DialogInterface.OnClickListener() {
//cancels
}
}); // create alert dialog show it
}
public void hitLocation( final double dialogLat, final double dialogLng){
LocationListener ll = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
double lat = location.getLatitude();
double lon = location.getLongitude();
final LatLng currentLatLon = new LatLng(lat, lon);
//tracks weather or not person hit the location
if((lat > (dialogLat- 0.0001) && lat < (dialogLat+ 0.0001)) &&
(lon > (dialogLon - 0.0001) && lon < (dialogLon + 0.0001))){
dialogMarker = map.addMarker(new MarkerOptions().position(currentLatLon)
}
} // other location listener methods
直到我在 onClick 方法中为警报对话框传递 hitLocation(doubleLat,doubleLng) 为止。我认为应该发生的是,当我在地图上放置一个标记时,hitLocation 应该检查我是否真的击中了用户设置的位置。
【问题讨论】:
-
完全不清楚你所说的“这一切都取决于我检查我是否通过标记的部分。”。我看不到您在哪里检查是否有任何通过的标记。您正在调用方法 hitLocation();但我们所看到的只是 hitLocation(double, double); 的方法签名; ...我认为您需要提供更多信息和更多代码
-
使用正确的 hitLocation 参数进行编辑。对于 hitLocation,我想输入用户在触摸地图时留下的 lat 和 lng 坐标,并且用户绕过该区域,然后在用户之前触摸的区域上应显示一个红色标记。跨度>
标签: java android google-maps google-maps-api-2