I want to add markers when ever on camera change listener is called.
@Override
public void onCameraChange(CameraPosition position) {
// TODO Auto-generated method stub
double[] newValues = { position.target.latitude,
position.target.longitude };
new GetPlaces().execute(newValues);
}
AsyncTask Class which is used to get the center location of the map and get known places arround that location
private class GetPlaces extends AsyncTask<double[], Void, Boolean> {
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
}
@Override
protected Boolean doInBackground(double[]... params) {
// TODO Auto-generated method stub
double[] vals = params[0];
HttpRequest request = new HttpRequest();
try {
locs = request.getPlaces(vals[0], vals[1]);
return true;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
}
@Override
protected void onPostExecute(Boolean result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
if (result) {
if (mMap != null) {
if (locs.size() > 0) {
mMap.clear();
for (com.matsoltech.android.apps.easysavinghunter.Location loc : locs) {
Log.e("APPLICATION", "LOCATIONS FOUND ");
mMap.addMarker(new MarkerOptions()
.position(
new LatLng(loc.getPoint()
.getLatitude(), loc
.getPoint().getLongitude()))
.title(loc.getName())
.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
}
} else {
Toast.makeText(MainActivity.this, "No Deal Found",
Toast.LENGTH_LONG).show();
}
} else {
Log.e("APPLICATION", "MAP IS NULL");
}
} else {
Toast.makeText(
MainActivity.this,
"Oops..Something went wrong. Please check your connection and try again",
Toast.LENGTH_LONG).show();
}
}
}
In logcat the values are correct and data is being fetched properly .. the only problem is that my markers are not showing on the map. Please help!!
The answer is that i wasn't putting the right values of Lat and Lng in the Point object. Now its working find!!
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加