Adh*_*elB 2 android json geojson
我目前正在使用Google Maps API,并且尝试将带有标记的GEOJSON文件作为图层连接到地图。
我从文档中摘录的行现在正在尝试使用:
GeoJsonLayer layer = new GeoJsonLayer(getMap(), R.raw.geoJsonFile,
getApplicationContext());
Run Code Online (Sandbox Code Playgroud)
错误是 Cannot resolve symbol 'GeoJsonLayer'
我已经将编译添加org.json:json:20090211到了我的依赖项中,但这并没有解决问题。
我正在使用Android Studio为Android OS编码。
有什么帮助吗?谢谢
编辑:
班级代码:
package com.example.macbookair........;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.maps.android.geojson.GeoJsonLayer;
import org.json.JSONException;
import java.io.IOException;
public class Maps extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
private GeoJsonLayer layer1;
@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;
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
/* MapFragment mapFrag = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
try {
GeoJsonLayer layer1 = new GeoJsonLayer(mapFrag.getMap(), R.raw.mapjson,
getApplicationContext());
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
layer1.addLayerToMap(); */
// Add a marker in Sydney and move the camera
}
}
Run Code Online (Sandbox Code Playgroud)
代码的注释部分可以正常工作,但会使应用程序崩溃,没有注释的代码,地图可以正常工作并可以在我的设备上正常加载。
您需要google-maps-utils在build.gradle文件中添加。
dependencies {
implementation 'com.google.maps.android:android-maps-utils:x.y.z'
}
Run Code Online (Sandbox Code Playgroud)
其中xyz是版本。最新的是:0.4。
您还可能需要google-maps依赖项(和play-services-base),并且可以将其添加到build.gradle文件中,如下所示:
dependencies {
implementation 'com.google.maps.android:android-maps-utils:x.y.z'
implementation 'com.google.android.gms:play-services-maps:8.3.0'
implementation 'com.google.android.gms:play-services-base:8.3.0'
}
Run Code Online (Sandbox Code Playgroud)
如果要从play-services中获取所有库,则可以跳过这两个依赖关系并添加所有play-services依赖关系,如下所示:
implementation 'com.google.android.gms:play-services:8.3.0'
Run Code Online (Sandbox Code Playgroud)
请记住,这会将所有播放服务库添加到您的APK中,这可能会导致64k方法限制和更大的APK大小。
| 归档时间: |
|
| 查看次数: |
1589 次 |
| 最近记录: |