Reputation: 391
I was try to implement automatic right zoom level to show all markers. But, I' getting Null Pointer exception. Here is my code :
public class LocationMarkers extends FragmentActivity {
private static GoogleMap supportMap;
private ArrayList<LatLng> gp = new ArrayList<LatLng>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.location_marker);
locationMarkers();
}
public void locationMarkers()
{
/*Implement Location Markers*/
BufferedReader jsonReader = new BufferedReader(new InputStreamReader(this.getResources().openRawResource(R.raw.map)));
StringBuilder jsonBuilder = new StringBuilder();
try {
for (String line = null; (line = jsonReader.readLine()) != null;) {
jsonBuilder.append(line).append("\n");
}
JSONTokener tokener = new JSONTokener(jsonBuilder.toString());
JSONArray jsonArray = new JSONArray(tokener);
for (int index = 0; index < jsonArray.length(); index++)
{
JSONObject jsonObject = jsonArray.getJSONObject(index);
double getLat = jsonObject.getJSONObject("point").getDouble("lat");
double getLng = jsonObject.getJSONObject("point").getDouble("long");
String name = jsonObject.getString("name");
LatLng myLoc = new LatLng(getLat, getLng);
gp.add(myLoc);
Log.d("Long", Double.toString(getLng));
FragmentManager fmanager = getSupportFragmentManager();
Fragment fragment = fmanager.findFragmentById(R.id.map);
SupportMapFragment supportmapfragment = (SupportMapFragment)fragment;
supportMap = supportmapfragment.getMap();
if(supportMap!=null){
Marker LocMarker = supportMap.addMarker(new MarkerOptions().position(myLoc)
.title(name));
}
}
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for(LatLng m : gp) {
Log.e("Tag",Double.toString(m.latitude));
builder = builder.include(m);
}
LatLngBounds bounds = builder.build();
int padding = 0;
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 0);
supportMap.moveCamera(cu);
} catch (FileNotFoundException e) {
Log.e("jsonFile", "file not found");
} catch (IOException e) {
Log.e("jsonFile", "ioerror");
} catch (JSONException e) {
Log.e("jsonFile", "error while parsing json");
}
}
}
I'm also getting another warning : Google Play services out of date. Requires 2012100 but found 1015
I will be happy, If you guys help to find the problem?
Upvotes: 1
Views: 3464
Reputation: 3316
1) hope you are testing on device not in emulator. you may get error in emulator, if you still want to test on emulator then comment it. it will work in device perfectly
2) you are getting Google Play services out of date because your google play service library version is not same as your emulator google play service has. you have to install updated gms and vending apk file.
gms: http://uploaded.net/file/bnzl1si4
vending: http://www.androidfilehost.com/?fid=9390135922294521859
hope it will help you.
Upvotes: 4