0
我有開發一個簡單的應用程序,我一直在使用這種簡單的方式整合了谷歌地圖:`Android的谷歌地圖設置樣式地圖使用JSON
mapFragment.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
mClusterManager = new ClusterManager<Car2GoClusterItem>(getActivity(), map);
map.setOnCameraChangeListener(mClusterManager);
map.setInfoWindowAdapter(mClusterManager.getMarkerManager());
map.setOnMarkerClickListener(mClusterManager);
mClusterManager.setOnClusterItemClickListener(
new ClusterManager.OnClusterItemClickListener<Car2GoClusterItem>() {
@Override
public boolean onClusterItemClick(Car2GoClusterItem item) {
clickedClusterItem = item;
return false;
}
});
});
}
public GoogleMap.OnCameraChangeListener getCameraChangeListener() {
return new GoogleMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition position) {
Log.d("Zoom", "Zoom: " + position.zoom);
if (previousZoomLevel <= 15 && position.zoom > 15) {
map.clear();
processMap(v, 16);
}
if (previousZoomLevel >= 15 && position.zoom < 15) {
map.clear();
processMap(v, 14);
}
previousZoomLevel = position.zoom;
}
};
}
public void processMap(View v, int zoom) {
if (map == null) {
map = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map))
.getMap();
}
if (map != null) {
//// code here
}
}
現在我想爲我的映象的MapStyle通過設置JSON和我看到這個代碼:
public void onMapReady(GoogleMap googleMap) {
// Customise the styling of the base map using a JSON object defined
// in a string resource file. First create a MapStyleOptions object
// from the JSON styles string, then pass this to the setMapStyle
// method of the GoogleMap object.
boolean success = googleMap.setMapStyle(new MapStyleOptions(getResources()
.getString(R.string.style_json)));
if (!success) {
Log.e(TAG, "Style parsing failed.");
}
// Position the map's camera near Sydney, Australia.
googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(-34, 151)));
}
,但我不知道如何整合,因爲這是樣的活動,而不是我用一個片段,也當我打算進軍添加以下代碼給我一個錯誤。 有什麼幫助嗎? 感謝
你在哪裏得到錯誤的代碼? –