Issue
I am using onMapReady() function which gets called at the start of MapActivity which implements OnMapReadyCallback.
It has a spinner at the top on whose change of item I refresh values of particular region / country and it should get reflected in title after onPostExecute() .
All the things till onPostExecute() method of AsyncTask works fine in which I call again onMapReady(mMap) function to display new values , but it does not work
Below is my code
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() Function
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));
}
}
}
Solution
Missed out on mMap.clear()
before updating Map .
Answered By - Yatin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.