문제 설명
'GeoJsonLayer' 기호를 확인할 수 없습니다. (Cannot resolve symbol 'GeoJsonLayer ')
현재 Google Maps API를 사용 중이며 마커가 있는 GEOJSON 파일을 지도에 레이어로 연결하려고 합니다.
문서에서 가져온 줄과 현재 시도 중인 사용:
GeoJsonLayer layer = new GeoJsonLayer(getMap(), R.raw.geoJsonFile,
getApplicationContext());
오류는 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
}
}
코드의 주석 처리된 부분은 작동하지만 주석 처리된 코드가 없으면 지도가 제대로 작동하고 애플리케이션 충돌이 발생합니다. 내 기기에서 잘 로드됩니다.
참조 솔루션
방법 1:
You need to add the google‑maps‑utils
in your build.gradle
file.
dependencies {
implementation 'com.google.maps.android:android‑maps‑utils:x.y.z'
}
Where x.y.z is the version. The latest one is: 0.4
.
You can also need the google‑maps
dependency (and play‑services‑base), and can be added in build.gradle file as listed:
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'
}
If you want all the libraries from play‑services, you can skip these two dependencies and add all play‑services dependencies, like this:
implementation 'com.google.android.gms:play‑services:8.3.0'
Remember that this will add all play‑services libs into your APK, and this may cause a 64k method limit and bigger APK size.
Reference to install play‑services
Reference to Google Maps Utils
방법 2:
Make sure you have added dependencies mentioned by Deividi Cavarzan
Plus make sure your mapjson file format is correct
Check for this geojson file code :
{
"type": "FeatureCollection",
"features": [{ "type": "Feature",
"geometry": {
"type": "Point",
"coordinates":
[102.0, 0.5]
},
"properties": {
"prop0": "value0"
}
}, {
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[102.0, 0.0],
[103.0, 1.0],
[104.0, 0.0],
[102.0, 0.0]
]
},
"properties": {
"prop0": "value0",
"prop1": 0.0
}
}
]
}
To check whether your GeoJson file is correct or not visit : http://geojsonlint.com/
(by AdheelB、Deividi Cavarzan、Lakhani Aliraza)
참조 문서