gpt4 book ai didi

java - 当用户将标记添加到 map 上时,如何访问标记?

转载 作者:太空宇宙 更新时间:2023-11-04 14:38:43 25 4
gpt4 key购买 nike

当用户单击 map 上的某个位置时,会打开一个对话框警报框,提示用户是否要添加标记,如果是,则添加标记。我正在尝试编写另一种方法,如果用户通过此标记,则标记会改变颜色。

我在编写其中的标记检查部分时遇到问题。

我的代码:

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) 的位置。我认为应该发生的是,当我在 map 上放置标记时,hitLocation 应该检查我是否确实到达了用户设置的位置。

最佳答案

确实不清楚这一切是如何结合在一起的(至少对我来说)。例如,我什至不知道 hitLocation(double, double) 是如何调用的,但我确实看到了一些问题。

首先。这是拼写错误吗?

    if((lat > (dialogLat- 0.0001) && lat < (dialogLng+ 0.0001)) 

你的意思是

    if((lat > (dialogLat- 0.0001) && lat < (dialogLat+ 0.0001)) 

对话框**Lat** 与对话框**Lng**

我认为你最好使用这样的东西来检查坐标是否接近。

Math.abs(value1 - value2) < someTolerance

纬度和经度并不总是正数。

关于java - 当用户将标记添加到 map 上时,如何访问标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25235683/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com