i'm trying to add markers to my map, the coordinates and names are contained in a stop object that i'm getting through a query to a stackmob database, the program runs fine displays the map, but for some reason it looks like its not executing the addmarker instruction, won't even loop through the for in the addMarkers method. Also i'm not getting errors or messages of any kind in the console or LogCat, i'm running out of ideas to solve this.
public class MainActivity extends Activity {
GoogleMap map;
List<Stop> stops=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
StackMobAndroid.init(getApplicationContext(), 0, "f4e013f5-3e0f-41e2-af2f-3fc2bfa2446b");
getMarkers();
}
public void getMarkers( )
{
Stop.query(Stop.class, new StackMobQuery().field(new StackMobQueryField("stop")), new StackMobQueryCallback<Stop>() {
@Override
public void success(List<Stop> result) {
addMarkers(result);
}
@Override
public void failure(StackMobException e) {
System.out.println("Fail");
}
});
}
public void addMarkers(List<Stop> stops)
{
for(int i=0;i<=stops.size();i++)
{
LatLng markerPos = new LatLng(stops.get(i).getLatitude(), stops.get(i).getLongitude());
System.out.println(markerPos);
System.out.println(stops.get(i).getName());
System.out.println(i);
map.addMarker(new MarkerOptions().title(stops.get(i).getName()).snippet("test").position(markerPos));
}
}
Thanks
Edit: If i add a a marker manually in, lets say the onCreate method, it will display correctly on the map.
Edit2: When i put a try catch statement around the map.addmarker the error message reads "Not on the main thread" not sure about this.