'GeoJsonLayer' 기호를 확인할 수 없습니다. (Cannot resolve symbol 'GeoJsonLayer ')


문제 설명

'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 AdheelBDeividi CavarzanLakhani Aliraza)

참조 문서

  1. Cannot resolve symbol 'GeoJsonLayer ' (CC BY‑SA 2.5/3.0/4.0)

#geojson #JSON #Android






관련 질문

Geodjango GeoJSON 직렬 변환기 기하학은 항상 'null'입니다. (Geodjango GeoJSON Serializer geometry always 'null')

전단지에서 레이어 켜기/끄기(더 복잡한 시나리오) (Toggle layers on and off in Leaflet (more complex scenario))

RethinkDB r.polygon() - GeoJSON LinearRing에는 최소 4개의 위치가 있어야 합니까? (RethinkDB r.polygon() - GeoJSON LinearRing must have at least four positions?)

Leaflet : GeoJSON 속성에서 GeoJSON 레이어 설정 아이콘 (Leaflet : setting icon for GeoJSON layer from GeoJSON property)

'GeoJsonLayer' 기호를 확인할 수 없습니다. (Cannot resolve symbol 'GeoJsonLayer ')

스키마의 mongoose geojson, "지역 키를 추출할 수 없습니다" 오류 (mongoose geojson in schema, "Can't extract geo keys" error)

Android Google 지도는 GeoJSON을 사용하여 마커를 설정합니다. (Android Google Maps set marker using GeoJSON)

GraphQl로 geojson 포인트를 쿼리하는 방법은 무엇입니까? (How to query a geojson point with GraphQl?)

geojson 포인트 데이터 마커가 전단지 맵에서 클러스터링되지 않습니다. (The geojson point data markers are not clustering in leaflet map)

전단지 geoJSON.onEachFeature는 함수가 아닌가요? (leaflet geoJSON.onEachFeature is not a function?)

Folium에서 특정 국가 강조 표시 (Highlight one specific country in Folium)

RGeo 및 Geojson으로 면적 계산 (Calculating area with RGeo and Geojson)







코멘트