2016-09-30 24 views
0

我試圖在我的應用程序的地圖中實現自定義顏色方案。所以我根據谷歌的指示,在onMapReady()函數內部調用了一個自定義的JSON(JSON是由google提供的工具創建的)。我onMapready函數如下給出在Android地圖v2中創建自定義樣式的地圖時無法解析setMapStyle()

@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(
          this, R.raw.style_json)); 

      if (!success) { 
       Log.e("MapsActivityRaw", "Style parsing failed."); 
      } 
     } catch (Resources.NotFoundException e) { 
      Log.e("MapsActivityRaw", "Can't find style.", e); 
     } 
    } 

但無論我嘗試它顯示函數setMapStyle()中的錯誤。

error

我在機器人編程初學者,所以如果它甚至..我已經搜索了很多得到sollution的那種小顯而易見的解決方案請你幫助..

在此先感謝

+0

'GoogleMap'不提供'setMapStyle( ...)方法 –

+0

那麼這篇文章怎麼樣https://developers.google.com/maps/documentation/android-api/styling –

+1

更新你在build.gradle中播放服務版本 –

回答

3

正如@MD所說,您需要更新您的build.gradle才能使用Play Services的最新版本。目前的版本是9.6.1

dependencies { 
    compile 'com.google.android.gms:play-services:9.6.1' 
} 

更新後,你build.gradle你就能地圖樣式,但考慮到,作爲the documentation說,造型只適用於普通地圖類型。

+0

感謝隊友讓我試試看...現在這裏的互聯網有點慢...所以需要一段時間下載...所以我會更新它,如果這樣做的工作...感謝您的幫助 –

0

無法解析googleMap.setMapStyle()固定

更新所有谷歌播放服務9.8.0解決我的問題

dependencies { 

    compile fileTree(include: ['*.jar'], dir: 'libs') 
    testCompile 'junit:junit:4.12' 
    compile 'com.google.firebase:firebase-messaging:9.8.0' 
    compile 'com.google.android.gms:play-services-maps:9.8.0' 
    compile 'com.google.android.gms:play-services-location:9.8.0' 
    compile 'com.google.firebase:firebase-database:9.8.0' 
    compile 'com.google.firebase:firebase-auth:9.8.0' 
    compile 'com.google.firebase:firebase-crash:9.8.0' 
    compile 'com.google.maps.android:android-maps-utils:0.4.4' 
    compile 'com.google.android.gms:play-services-appindexing:9.8.0' 

} 

apply plugin: 'com.google.gms.google-services'