实时添加多个标记 google 地图 v2 android

Adding Multiple Markers in real time google maps v2 android

我想在调用相机更改侦听器时添加标记。

@Override
public void onCameraChange(CameraPosition position) {
    // TODO Auto-generated method stub
    double[] newValues = { position.target.latitude,
            position.target.longitude };
    new GetPlaces().execute(newValues);
}

AsyncTask Class 用于获取地图的中心位置并获取该位置周围的已知地点

private class GetPlaces extends AsyncTask<double[], Void, Boolean> {

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();

    }

    @Override
    protected Boolean doInBackground(double[]... params) {
        // TODO Auto-generated method stub
        double[] vals = params[0];
        HttpRequest request = new HttpRequest();
        try {
            locs = request.getPlaces(vals[0], vals[1]);
            return true;
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return false;
        }

    }

    @Override
    protected void onPostExecute(Boolean result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);

        if (result) {
                if (mMap != null) {
            if (locs.size() > 0) {


                    mMap.clear();

                    for (com.matsoltech.android.apps.easysavinghunter.Location loc : locs) {

                        Log.e("APPLICATION", "LOCATIONS FOUND ");
                        mMap.addMarker(new MarkerOptions()
                                .position(
                                        new LatLng(loc.getPoint()
                                                .getLatitude(), loc
                                                .getPoint().getLongitude()))
                                .title(loc.getName())
                                .icon(BitmapDescriptorFactory
                                        .defaultMarker(BitmapDescriptorFactory.HUE_RED)));
                    }

                } else {
                    Toast.makeText(MainActivity.this, "No Deal Found",
                            Toast.LENGTH_LONG).show();
                }
            } else {
                Log.e("APPLICATION", "MAP IS NULL");
            }
        } else {
            Toast.makeText(
                    MainActivity.this,
                    "Oops..Something went wrong. Please check your connection and try again",
                    Toast.LENGTH_LONG).show();
        }
    }
}

在 logcat 中,值是正确的并且正在正确获取数据。唯一的问题是我的标记没有显示在地图上。请帮忙!!

答案是我没有在 Point 对象中输入正确的 Lat 和 Lng 值。现在找到了!