我想創建一個使用谷歌地圖的Android應用程序。我使用了Google Maps APIs Styling Wizard並創建了json文件。爲了應用更改,我必須在我的應用的代碼(android studio)中做出哪些更改?造型谷歌地圖
Q
造型谷歌地圖
1
A
回答
1
地圖準備就緒後,你可以申請風格變化OnMapReady
@Override
public void onMapReady(GoogleMap map) {
mMap = map;
setMapStyle();
}
private void setMapStyle() {
MapStyleOptions style = new MapStyleOptions("[" +
" {" +
" \"featureType\":\"poi.business\"," +
" \"elementType\":\"all\"," +
" \"stylers\":[" +
" {" +
" \"visibility\":\"off\"" +
" }" +
" ]" +
" }," +
" {" +
" \"featureType\":\"transit\"," +
" \"elementType\":\"all\"," +
" \"stylers\":[" +
" {" +
" \"visibility\":\"off\"" +
" }" +
" ]" +
" }" +
"]");
mMap.setMapStyle(style);
}
檢查這些鏈接:MapStyleOptions,GoogleSamples
2
添加自定義樣式,以谷歌地圖是很容易的。檢查下面的代碼。
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
try {
// Customise the styling of the base map using a JSON object defined
// in a raw resource file.
boolean success = mMap.setMapStyle(
MapStyleOptions.loadRawResourceStyle(
MapsActivity.this, R.raw.style_json));
if (!success) {
Log.e("Map", "Style parsing failed.");
}
} catch (Resources.NotFoundException e) {
Log.e("Map", "Can't find style.", e);
}
}
}
在res /文件夾下創建一個文件夾名稱raw。將json從google maps api樣式嚮導複製並粘貼到style_json文件並將其添加到原始文件夾中。而已。風格將被應用。檢查這example。
1
內部創建res/一個名爲raw的目錄。在原始創建文件name.json並把JSON從Google Maps APIs Styling Wizard裏面
在onMapReady(GoogleMap的GoogleMap的)方法把這些代碼
googleMap.setMapStyle(
MapStyleOptions.loadRawResourceStyle(
this, R.raw.name.json));
,它是所有:)
相關問題
- 1. 谷歌地圖GeoJson造型
- 2. 造型谷歌地圖InfoWindow
- 3. 麻煩造型我的谷歌地圖
- 4. 造型谷歌地圖API窗口
- 5. 谷歌地圖造型查詢
- 6. 谷歌地圖API造型錯誤
- 7. 谷歌地圖谷歌地點類型
- 8. 造型谷歌折線圖
- 9. 谷歌地圖地方搜索標記圖標造型
- 10. Java谷歌地圖谷歌地圖
- 11. 谷歌地圖用CSS「改造:規模」
- 12. 谷歌地圖v3 - 土地類型
- 13. 谷歌地圖默認tiptool傾斜箭頭造型
- 14. 造型谷歌地球插件邊界圖層
- 15. 造型標準谷歌地圖v3中的縮放控件
- 16. 造型谷歌地圖API的多段線
- 17. 谷歌地圖的JavaScript API - 造型建築
- 18. 使用API V3的造型/主題谷歌地圖
- 19. 谷歌地圖的造型師不起作用?
- 20. 谷歌地圖Api V3 - 造型國家或城市
- 21. jQuery的谷歌地圖造型器屬性
- 22. HTML- /造型谷歌地圖api v3的工具提示
- 23. 造型谷歌地圖 - JavaScript API v3 - 海岸線概述?
- 24. 谷歌表格造型
- 25. 谷歌地圖
- 26. 谷歌地圖
- 27. 谷歌地圖
- 28. 谷歌地圖
- 29. 谷歌地圖
- 30. 谷歌地圖:地圖