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

时间:2015-02-13 01:33:12

标签: android google-maps google-maps-markers

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

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

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

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中,值正确并正在正确获取数据..唯一的问题是我的标记没有在地图上显示。请帮忙!!

1 个答案:

答案 0 :(得分:0)

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