Android 当I';我要走了

Android 当I';我要走了,android,google-maps,google-maps-markers,Android,Google Maps,Google Maps Markers,我是Android应用程序开发的初学者 我通过web服务检索数据并在地图上放置标记,现在我想知道如何将标记(蓝色标记:“BitmapDescriptorFactory.fromResource(R.drawable.blue_标记)”更改为橙色标记:“BitmapDescriptorFactory.fromResource.drawable.orange_标记”)​​如果我移动时这些标记在半径小于500米的范围内。我的第一个代码工作了,但我必须离开活动,然后回来让更改生效。我希望它是动态的

我是Android应用程序开发的初学者

我通过web服务检索数据并在地图上放置标记,现在我想知道如何将标记(蓝色标记:“BitmapDescriptorFactory.fromResource(R.drawable.blue_标记)”更改为橙色标记:“BitmapDescriptorFactory.fromResource.drawable.orange_标记”)​​如果我移动时这些标记在半径小于500米的范围内。我的第一个代码工作了,但我必须离开活动,然后回来让更改生效。我希望它是动态的

    ArrayList<StopModel> stopList;
    ArrayList<StopModel> a;
    Marker m;
    ArrayList<Marker> mList;
    Marker locationMarker;
    Location mLastLocation;

    public class Stuff extends AppCompatActivity implements OnMapReadyCallback,
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener, LocationListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        /*
        * lots of stuff here
        */


        mList = new ArrayList<>();
        a = new ArrayList<>();


        try {

            //retrieving markers
            a = new GetStops() {
            }.execute().get();

        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }
    }


        /*
        * lots of stuff here
        */


    @Override
    public void onLocationChanged(Location location) {

        mLastLocation = location;

        mGoogleMap.clear();
        LatLng ll = new LatLng(mLastLocation.getLatitude(), mLastLocation.getLongitude());

        for (int i = 0; i < a.size(); i++) {
            m = createMarker(a.get(i).getPosition(), a.get(i).getArretCode(), a.get(i).getQuartier());
            mList.add(m);
        }

        //I'm trying to use the mList to change markers color when I'm nearby
        changeMarkerColor(ll, mList);


    }


    private class GetStops extends AsyncTask<Void, Void, ArrayList<StopModel>> {

        @Override
        protected ArrayList<StopModel> doInBackground(Void... voids) {

            HttpHandler httpHandler = new HttpHandler();
            String jsonString = null;


            String url = myWebServiceURL;
            jsonString = httpHandler.makeServiceCall(url);

            try {

                JSONArray jsonArray = new JSONArray(jsonString);

                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject jsonObject = jsonArray.getJSONObject(i);

                    StopModel stopModel = new StopModel();

                    stopId = jsonObject.getString("stopId");
                    stopCode = jsonObject.getString("stopCode");
                    stopPosition = new LatLng(jsonObject.getDouble("stopLat"), jsonObject.getDouble("stopLong"));

                    stopModel.setId(stopId);
                    stopModel.setCode(stopCode);
                    stopModel.setPosition(stopPosition);


                    stopList.add(stopModel);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return stopList;
        }

        @Override
        protected void onPostExecute(ArrayList<stopModel> stopModels) {
            super.onPostExecute(stopModels);

        }
    }


    protected Marker createMarker(LatLng latLng, String title, String snippet) {


        locationMarker = mGoogleMap.addMarker(new MarkerOptions()
                .position(latLng)
                .anchor(0.5f, 0.5f)
                .title(title)
                .snippet(snippet)
                .icon(BitmapDescriptorFactory.fromResource(R.drawable.blue_marker)));

        return locationMarker;
    }

    void changeMarkerColor(LatLng myPos, ArrayList<Marker> markerList) {
        for (Marker m : markerList)
            if (SphericalUtil.computeDistanceBetween(myPos, m.getPosition()) < 500) {
                m.setTitle(getDistance(myPos, m.getPosition()));
                showToast(getDistance(myPos, m.getPosition()));
                m.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.orange_marker));

            }

    }

 }
ArrayList停止列表;
ArrayList a;
标记m;
阵列列表;
标记定位标记;
位置mLastLocation;
公共类Stuff扩展了AppCompatActivity在MapReadyCallback上的实现,
GoogleAppClient.ConnectionCallbacks,
GoogleAppClient.OnConnectionFailedListener,LocationListener{
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
/*
*这里有很多东西
*/
mList=新的ArrayList();
a=新的ArrayList();
试一试{
//检索标记
a=新的GetStops(){
}.execute().get();
}捕获(中断异常|执行异常e){
e、 printStackTrace();
}
}
/*
*这里有很多东西
*/
@凌驾
已更改位置上的公共无效(位置){
mLastLocation=位置;
mGoogleMap.clear();
LatLng ll=新LatLng(mLastLocation.getLatitude(),mLastLocation.getLatitude());
对于(int i=0;i