0

マップ上にマーカーを表示しようとしています。これは、MySQLデータベースからマーカーを取得して、asynctaskでJSONを使用して取得しています。ログで次のように取得しています。私はそれがGoogle証明書と関係があると思っていますが、わかりません。このコードは、古いバージョンのandroid <では動作しますが、新しいバージョンでは動作しません。ここ 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文が実行されていない可能性があります。

アプリのgradleでtarget_sdk 22を設定して確認してください。

これはテスト用です。マップオブジェクトでmylocationenabled(true)にアクセスする前に、アクセス権を要求するためのコードを実行する必要があります。

0

場所のアクセス許可が付与されているかどうかを確認する必要があります。 AysncTaskの実行前にコード内にreturn文があるので、おそらくタスクを実行していません。

ロケーションのアプリケーション設定を許可し、動作するかどうかを確認してください。

あなたのコードでもmarshmallow以降のアクセス許可を処理する必要があります。

関連する問題