我正在使用onMapReady()函数,该函数在实现OnMapReadyCallback的MapActivity的开头被调用。
在顶部有一个微调器,其中项目I的更改刷新特定区域/国家/地区的值,它应该在onPostExecute()之后反映在标题中。
AsyncTask的onPostExecute()方法之前的所有工作正常,我再次调用onMapReady(mMap)函数来显示新值,但它不起作用
以下是我的代码
void callExchangeRateWebService() {
CommonMethods.showProgressDialog(MapsActivity.this, "", "Fetching Exchange Rates...");
new WebServiceCallTask(MapsActivity.this, "" + MantraSoapLinks.URL2+((CountryBean)(mSpinner1.getSelectedItem())).getmCountrySymbol(),"", "GET", "" ,new WebServiceCallBack() {
@Override
public void onSuccess(Object result) throws JSONException {
CommonMethods.hideProgressDialog(MapsActivity.this);
JSONObject jObj = new JSONObject(result.toString());
JSONObject ratesObj = jObj.getJSONObject("rates");
String baseStr = jObj.getString("base");
String temp = ratesObj.toString().replace("{","");
temp = temp.toString().replace("}","");
temp = temp.toString().replace("\"","");
temp = temp.toString().replace("\"","");
String[] str= temp.split(",");
ArrayList<String> arry = new ArrayList<String>();
for (int i = 0 ;i <str.length;i++)
{
arry.add(str[i]);
}
arry.add(baseStr+":1");
String [] str1 = new String[arry.size()];
for (int i = 0 ;i <arry.size();i++)
{
str1[i] = arry.get(i).toString();
}
for(int i = 0 ; i<str1.length ; i++)
{
CountryBean cn = new CountryBean();
cn.setmCountrySymbol((str1[i].split(":"))[0]);
cn.setmCurrencyValueMap((str1[i].split(":"))[1]);
db.updateCountryDetails(cn);
}
beanArry = db.getCountryDetails();
onMapReady(mMap);
}
@Override
public void onFailed(Object result) {
CommonMethods.hideProgressDialog(MapsActivity.this);
}
}).execute();
}
onMapReady()函数
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
/*// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
LatLng testindiA = new LatLng(-20, 150);
mMap.addMarker(new MarkerOptions().position(testindiA).title("Yatin Test"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(testindiA));*/
for (int i = 0;i<beanArry.size();i++)
{
LatLng ltLn = null;
if(beanArry.get(i).getmLatitude()!=null) {
ltLn = new LatLng(Double.parseDouble(beanArry.get(i).getmLatitude()), Double.parseDouble(beanArry.get(i).getmLongitude()));
mMap.addMarker(new MarkerOptions().position(ltLn).title(beanArry.get(i).getmCountryName()+" "+beanArry.get(i).getmCurrencyValueMap()));
String str = beanArry.get(i).getmCountryName();
str = str.toLowerCase();
str = str.replace(" ","_");
String PACKAGE_NAME =getApplicationContext().getPackageName();
int imgId = getResources().getIdentifier(PACKAGE_NAME+":drawable/"+str , null, null);
if(imgId!=0) {
BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(imgId);
mMap.addMarker(new MarkerOptions().position(ltLn).icon(icon));
}
else
{
mMap.addMarker(new MarkerOptions().position(ltLn).icon(null));
}
mMap.moveCamera(CameraUpdateFactory.newLatLng(ltLn));
}
}
}
答案 0 :(得分:0)
在更新地图之前错过了mMap.clear()
。