在谷歌地图v2中的Zoomlevel中出现多个地方标记android的问题

时间:2015-05-25 06:13:31

标签: android google-maps zoom google-maps-api-2

我想按照kiometer半径设置我的缩放级别,并设置多个位置标记,因此设置为代码

public class getPlaceDatas extends AsyncTask<Void, Void, Void> {

    List<Marker> markers ;
    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();
        mProgressDialog = ProgressDialog.show(MainActivity.this, "Wait",
                "Loading..");
        // mProgressBar.setVisibility(View.VISIBLE);
    }

    @Override
    protected Void doInBackground(Void... params) {
        // TODO Auto-generated method stub
        mGetPlaceData = (GetPlaceData) mPostParseGet.getPlaces(
                mGetPlaceData, CurrentLatitude, CurrentLongitude,
                mDoubleKm, type);
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
        if (mProgressDialog != null) {
            mProgressDialog.dismiss();
        }

        // mProgressBar.setVisibility(View.GONE);
        if (mPostParseGet.isNetError) {
            mAllMethods.ShowDialog(MainActivity.this, "Network error ",
                    "Network not available", "OK");
        } else if (mPostParseGet.isOtherError) {
            mAllMethods
                    .ShowDialog(
                            MainActivity.this,
                            "Validation",
                            "Data not found due to slow internet connection or server problem .",
                            "OK");
        } else {
            if (mGetPlaceData.getLocations() != null
                    && !mGetPlaceData.getLocations().isEmpty()) {
                if (mGetPlaceData.getLocations().size() > 0) {
                    mArrayListPlaceListDatas = getMemberList();
                    if (mArrayListPlaceListDatas.size() > 0) {
                        mPlaceListAdapter = new PlaceListAdapter(
                                MainActivity.this, R.layout.row_place,
                                mArrayListPlaceListDatas);
                        mListViewPlaces.setAdapter(mPlaceListAdapter);
                        mTextViewCounter.setText(String
                                .valueOf(mArrayListPlaceListDatas.size()));
                        myMap.clear();
                        for (int i = 0; i < mArrayListPlaceListDatas.size(); i++) {

                            MarkerOptions markerOptions = new MarkerOptions();
                            final double lat = Double
                                    .parseDouble(mArrayListPlaceListDatas
                                            .get(i).getLattitude());
                            final double lng = Double
                                    .parseDouble(mArrayListPlaceListDatas
                                            .get(i).getLongitude());
                            final LatLng latLng = new LatLng(lat, lng);

                            GetPlaceData     firstEventInfo = new GetPlaceData(
                                    latLng, mArrayListPlaceListDatas.get(i)
                                            .getId(),
                                    mArrayListPlaceListDatas.get(i)
                                            .getPlace_name(),
                                    mArrayListPlaceListDatas.get(i)
                                            .getPlace_address(),
                                    mArrayListPlaceListDatas.get(i)
                                            .getPlace_type(),
                                    mArrayListPlaceListDatas.get(i)
                                            .getContact_no(),
                                    mArrayListPlaceListDatas.get(i)
                                            .getEmail_id(),
                                    mArrayListPlaceListDatas.get(i)
                                            .getWebsite_url(),
                                    mArrayListPlaceListDatas.get(i)
                                            .getPin_image());

                            Marker firstMarker = placeMarker(firstEventInfo);

                            eventMarkerMap = new HashMap<Marker, GetPlaceData>();

                            eventMarkerMap.put(firstMarker, firstEventInfo);



                        }
                        final View mapView = getSupportFragmentManager().findFragmentById(R.id.map).getView();
                        if (mapView.getViewTreeObserver().isAlive()) {
                            mapView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
                                @SuppressLint("NewApi")
                                @Override
                                public void onGlobalLayout() {
                                    LatLngBounds.Builder bld = new LatLngBounds.Builder();
                        for (int i = 0; i < mArrayListPlaceListDatas.size(); i++) {           
                                LatLng ll = new LatLng(Double.parseDouble(mArrayListPlaceListDatas.get(i).getLattitude()), Double.parseDouble(mArrayListPlaceListDatas.get(i).getLongitude()));
                                bld.include(ll);            
                        }
                        LatLngBounds bounds = bld.build();          
                        myMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));
                        mapView.getViewTreeObserver().removeGlobalOnLayoutListener(this);

                                }
                            });
                        }
                        makeCircle(mDoubleKm);
                        String ss = mGpsTracker.getLocationAddress();
                        System.out.println("ss " + ss);
                        BitmapDescriptor icon1 = BitmapDescriptorFactory
                                .fromResource(R.drawable.green);

                        startPerc = myMap.addMarker(new MarkerOptions()
                                .position(
                                        new LatLng(CurrentLatitude,
                                                CurrentLongitude))
                                .title(address).icon(icon1));



                    } else {
                        mTextViewCounter.setText("0");
                    }
                }
            } else {
                makeCircle(mDoubleKm);
                mTextViewCounter.setText("0");
                Toast.makeText(MainActivity.this,
                        "Data not found for selected values.",
                        Toast.LENGTH_LONG).show();
            }
        }

    }
 }

public void makeCircle(double radius)
{

     if (circle!=null) {
         circle.remove();
    }


    double r=radius*1000;
      circle = myMap.addCircle(new CircleOptions().center(new LatLng(CurrentLatitude, CurrentLongitude)).radius(r).strokeColor(Color.RED).strokeWidth(4.0f)); 
      circle.getCenter();
    circle.setVisible(true);

    getZoomLevel(circle);
}

public int getZoomLevel(Circle circle) {
    if (circle != null){
        double radius = circle.getRadius();
        double scale = radius / 500;
        zoomLevel =(int) (16 - Math.log(scale) / Math.log(2));
    }
    return zoomLevel;
    }

当我运行上面的代码时,我给了我输出如下图像 enter image description here

我想要下面的类型输出

enter image description here

所以任何想法我怎么能让它成为可能?你的所有建议都很明显。

1 个答案:

答案 0 :(得分:-1)

    CameraUpdate center=
    CameraUpdateFactory.newLatLng(new LatLng(40.76793169992044,
                                             -73.98180484771729));
CameraUpdate zoom=CameraUpdateFactory.zoomTo(15);

map.moveCamera(center);
map.animateCamera(zoom);