我有以下情况,我有课:
public class MapFragment extends SupportMapFragment implements OnMapReadyCallback
包括以下方法:
private void createMarkers(LatLng latLng) {
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latLng);
map.addMarker(markerOptions);
}
private LatLng getLatLngFromAddress(String address) {
Geocoder geocoder = new Geocoder(getActivity());
List<Address> addresses = new ArrayList<>();
LatLng latLng = null;
try {
addresses = geocoder.getFromLocationName(address, 1);
if(addresses == null) {
return null;
}
Address location = addresses.get(0);
latLng = new LatLng(location.getLatitude(), location.getLongitude());
} catch (IOException e) {
e.printStackTrace();
}
return latLng;
}
在这一点上,我有一个内部类,在这个类中我从sqlite下载doinbackground方法中的数据,在onpostexecute中我想在Map上放置标记。如何在onpostexecute中调用这两个方法(createmarkers和getlatlngfromaddress)?
private static class getDataTask extends AsyncTask<Void, Void, List<String>> {
private String currentDateForRequest = "";
private IRoutesStore database;
private List<String> allAddresses = new ArrayList<>();
public getDataTask(String currentDateForRequest, IRoutesStore database) {
this.currentDateForRequest = currentDateForRequest;
this.database = database;
}
@Override
protected List<String> doInBackground(Void... voids) {
//getData from database
}
@Override
protected void onPostExecute(List<String> addresses) {
for(String address: addresses) {
createMarkers(getLatLngFromAddress(address)); //I can"t call this methods
}
}
}
1条答案
按热度按时间z5btuh9x1#
全局生成Map并使用this.map