0

마커를 맵에 표시하려고합니다. 그것은 마커를 MySQL 데이터베이스에서 가져오고 asynctask에서 JSON을 사용하여 가져오고 로그에서 다음을 얻습니다. 나는 그것이 Google 인증서와 관련이 있다고 생각하지만 잘 모르겠습니다. 이 코드는 안드로이드 < 5의 이전 버전에서 작동하지만 최신 버전에서는 작동하지 않습니다. 여기 andorid 마커가 asynctask 맵을 표시하지 않습니다.

I/zzbx: Making Creator dynamically 
W/zygote: Skipping duplicate class check due to unrecognized classloader 
I/Google Maps Android API: Google Play services client version: 11020000 
I/Google Maps Android API: Google Play services package version: 11743470 
I/zygote: Do partial code cache collection, code=125KB, data=68KB 
I/zygote: After code cache collection, code=120KB, data=67KB 
I/zygote: Increasing code cache capacity to 512KB 
I/Choreographer: Skipped 66 frames! The application may be doing too much work on its main thread. 
W/Google Maps Android API: Deprecation notice: In a future release, indoor will no longer be supported on satellite, hybrid or terrain type maps. Even where indoor is not supported, isIndoorEnabled() will continue to return the value that has been set via setIndoorEnabled(), as it does now. By default, setIndoorEnabled is 'true'. The API release notes (https://developers.google.com/maps/documentation/android-api/releases) will let you know when indoor support becomes unavailable on those map types. 
D/EGL_emulation: eglMakeCurrent: 0x9a51aee0: ver 2 0 (tinfo 0x9a7ff8a0) 

      [ 12-18 19:32:33.017 6391: 6463 D/   ] 
      HostConnection::get() New Host Connection established 0x8abe1340, tid 6463 
D/EGL_emulation: eglCreateContext: 0x82ad6f60: maj 1 min 0 rcv 1 
D/EGL_emulation: eglMakeCurrent: 0x82ad6f60: ver 1 0 (tinfo 0x823a57e0) 
W/DynamiteModule: Local module descriptor class for com.google.android.gms.googlecertificates not found. 
W/zygote: Skipping duplicate class check due to unrecognized classloader 
I/DynamiteModule: Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:4 
I/DynamiteModule: Selected remote version of com.google.android.gms.googlecertificates, version >= 4 
W/zygote: Skipping duplicate class check due to unrecognized classloader 

당신은 당신의 조각이 그 시간을 만들 때 서버로 요청을 보낼 수 있도록 기록을 얻을에서 onCreate() 메소드에서 처음으로 API를 호출해야하고 내 코드

public class MapsActivity extends FragmentActivity implements  GoogleMap.OnMarkerClickListener, OnMapReadyCallback { 

private Marker marker; 
private GoogleMap mMap; 
public String lastClick; 


@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_SATELLITE); 
    mMap.setOnMarkerClickListener(this); 
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 
     // TODO: Consider calling 
     // ActivityCompat#requestPermissions 
     // here to request the missing permissions, and then overriding 
     // public void onRequestPermissionsResult(int requestCode, String[] permissions, 
     //           int[] grantResults) 
     // to handle the case where the user grants the permission. See the documentation 
     // for ActivityCompat#requestPermissions for more details. 
     return; 
    } 
    mMap.setMyLocationEnabled(true); 

    new AsyncTaskGetMareker().execute(); 
} 

public String getJSONFromAssets() { 
    String json = null; 
    try { 
     Intent intent = getIntent(); 
     final String cID = intent.getStringExtra("cID"); 
     InputStream inputData = new URL("someurlhere" + cID).openStream(); 
     int size = inputData.available(); 
     byte[] buffer = new byte[size]; 
     inputData.read(buffer); 
     inputData.close(); 
     json = new String(buffer, "UTF-8"); 
    } catch (IOException ex) { 
     ex.printStackTrace(); 
     return null; 
    } 
    return json; 
} 




private class AsyncTaskGetMareker extends AsyncTask<String, String, JSONArray> { 
    @Override 
    protected void onPreExecute() { 
     super.onPreExecute(); 
    } 

    @Override 
    protected JSONArray doInBackground(String... strings) { 
     String stationsJsonString = getJSONFromAssets(); 
     try { 
      JSONArray stationsJsonArray = new JSONArray(stationsJsonString); 
      return stationsJsonArray; 
     } catch (JSONException e) { 
      e.printStackTrace(); 
     } 
     //This will only happen if an exception is thrown above: 
     return null; 
    } 

    protected void onPostExecute(JSONArray result) { 
     if (result != null) { 
      for (int i = 0; i < result.length(); i++) { 
       JSONObject jsonObject = null; 
       try { 
        jsonObject = result.getJSONObject(i); 
        String name= jsonObject.getString("name"); 
        String lat = jsonObject.getString("lat"); 
        String lng = jsonObject.getString("lng"); 
        String occupied = jsonObject.getString("occupied"); 
        String id = jsonObject.getString("id"); 
        String hunb = jsonObject.getString("hunb"); 
        int occ = Integer.parseInt(occupied); 
        drawMarker(new LatLng(Double.parseDouble(lat), 
          Double.parseDouble(lng)), name, occ, id, hunb); 

       } catch (JSONException e) { 
        e.printStackTrace(); 
       } 
      } 
     } 

    } 

    private void drawMarker(LatLng point, String name, int occ, String id, String hunb) { 

     mMap.addMarker(new MarkerOptions() 
       .position(point) 
       .title(name) 
       .snippet(id) 
       .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED))); 

    } 

} 
} 

답변

0

입니다 다른 끝 google지도는 준비 할 것이다. 이 논리를 적용 해보십시오.

+0

oncreate와 onmapready에서 asynctask를 호출하는 중입니까? – frenchface

0

코드를 보면 위치 권한을 요청하지 않은 것으로 보입니다. 아마도 return 문으로 가고 map ready에 대한 asynctask 문이 실행되고 있지 않습니다.

target_sdk 22을 앱 그라데이션으로 설정하십시오.

이것은 테스트 목적으로 만 사용됩니다. map 객체에서 mylocationenabled (true)에 액세스하기 전에 권한 요청을위한 코드를 수행해야합니다.

0

위치 권한이 부여되는지 여부를 확인해야합니다. AysncTask를 실행하기 전에 코드에 return 문이 있으므로 작업을 실행하지 않은 것일 수 있습니다.

위치에 대한 응용 프로그램 설정 양식을 승인하고 작동하는지 확인해보십시오.

코드에서 marshmallow 이후 권한을 처리해야합니다.