gpt4 book ai didi

java - Android : java. lang.NullPointerException: CameraUpdateFactory 未初始化

转载 作者:行者123 更新时间:2023-11-29 03:32:51 27 4
gpt4 key购买 nike

我尝试实现自动右缩放级别以显示所有标记。但是,我得到空指针异常。这是我的代码:

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 服务已过时。需要 2012100 但找到 1015 如果你们能帮助找到问题,我会很高兴?

最佳答案

1) 希望您是在设备上而不是在模拟器中进行测试。你可能会在模拟器中出错,如果你仍然想在模拟器上测试然后评论它。它将在设备中完美运行

2) 您获取的 Google Play 服务已过时,因为您的 Google Play 服务库版本与您的 Google Play 服务模拟器不同。您必须安装更新的 gms 和自动售货机 apk 文件。

通用汽车公司: http://uploaded.net/file/bnzl1si4

贩卖: http://www.androidfilehost.com/?fid=9390135922294521859

希望对你有帮助。

关于java - Android : java. lang.NullPointerException: CameraUpdateFactory 未初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17182353/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com