0

Ich versuche, Marker zur Anzeige auf einer Karte zu erhalten. Es holt die Markierungen lat und long aus einer MySQL-Datenbank und ruft sie unter Verwendung von JSON in einer asynctask ab und ich erhalte Folgendes in den Protokollen. Ich denke, es hat mit dem Google-Zertifikat zu tun, aber ich bin mir nicht sicher. Dieser Code funktioniert bei älteren Versionen von Android < 5, aber nicht neueren Versionen.andorid Marker nicht asynctask Karten

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 

hier ist mein Code

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))); 

    } 

} 
} 

Antwort

0

Sie sollten die api in Anfang in onCreate() -Methode aufrufen, so dass, wenn Ihre Fragmente dieser Zeit schaffen es die Anforderung an den Server senden, um die Aufzeichnung zu erhalten und die Ein anderes Ende google map ist fertig. Bitte versuche diese Logik anzuwenden.

+0

Willst du sagen die asynctask im oncreate vs. onmapready aufrufen? – frenchface

0

Mit Blick auf Ihren Code scheint es, dass Sie keine Standortgenehmigung angefordert haben. Es geht vielleicht zu der Return-Anweisung und Ihre asynctask-Anweisung auf Map Ready wird nicht ausgeführt.

Überprüfen Sie dies, indem Sie target_sdk 22 in app gledle einrichten.

Dies ist nur für Testzwecke. Bevor Sie auf mylocationenabled (true) für das Kartenobjekt zugreifen, müssen Sie den Code zum Anfordern der Berechtigung eingeben.

0

Sie müssen überprüfen, ob die Berechtigung für den Standort erteilt wurde oder nicht. Da Sie eine Anweisung in Ihrem Code vor der Ausführung der AysncTask zurückgegeben haben, wird die Aufgabe wahrscheinlich nicht ausgeführt.

Versuchen Sie, das Erlaubnisformular für die Anwendungseinstellung für den Standort zu erteilen und prüfen Sie, ob es funktioniert.

Sie sollten die Erlaubnis für Marshmallow weiter in Ihrem Code behandeln.

Verwandte Themen