我试图实现自动右缩放级别以显示所有标记。但是,我得到空指针异常。这是我的代码:
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");
}
}
}
我也收到另一个警告:Google Play services out of date. Requires 2012100 but found 1015
我会很高兴,如果你们帮助找到问题?