Google Maps wird manchmal zu langsam und manchmal schnell geladen!

T

the_time

Ambitioniertes Mitglied
0
Hallo,
Ich versuch Daten an meine FragmentActvity zu übergeben aber ich habe das problem dass die Map FragmentActvity manschmal zu langsam und manschmal zu schnell:

Zu langsam: Erst wird die Afrika karte geladen und dann wird reingezommt. Außerdem habe ich here beim Debuggen gemerkt dass die onNewIntent in der FragmentActivity zu un zu unterschiedlichen Zeiten gerufen wird.)

Schnell: Afrika karte scheint nicht und es wird in einer Sekunde reingezommt.

Gibts eine Erklärung für dieses Verhalten?

Code in der IntenService:
Code:
                      if (data != null && !data.isEmpty()) {
                      // Also die Activity wird immer gerufen wenn Daten vorhanden sind.
                        Intent intent1 = new Intent(this, Map.class);
                        intent1.putExtra("list_data", data);
                        intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                                | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                        startActivity(intent1);
                  }

Map FragmentActivity:

Code:
    public class Map extends FragmentActivity implements OnMapReadyCallback {
        GoogleMap map;
   
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            if (servicesOK()) {
   
                setContentView(R.layout.map);
   
            } else {
                setContentView(R.layout.map_main);
   
            }
   
        }
   
        public boolean servicesOK() {
            int isAvailable = GooglePlayServicesUtil
                    .isGooglePlayServicesAvailable(this);
            if (isAvailable == ConnectionResult.SUCCESS) {
                return true;
            } else if (GooglePlayServicesUtil.isUserRecoverableError(isAvailable)) {
                Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable,
                        this, 9001);
                dialog.show();
   
            } else {
                Toast.makeText(this, "Cant't connect to Google Play services",
                        Toast.LENGTH_SHORT).show();
            }
            return false;
   
        }
   
        private boolean initMap() {
            if (map == null) {
                SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager()
                        .findFragmentById(R.id.map);
                map = mapFrag.getMap();
            }
            return (map != null);
        }
   
        private void gotoLocation(double lat, double lng, String route_direct) {
   
            SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.map);
            mapFragment.getMapAsync(this);
            final float zoom = 11;
            LatLng ll = new LatLng(lat, lng);
            if (lat != 0 && lng != 0 && !route_direct.isEmpty()) {
                MarkerOptions markerOpt = new MarkerOptions().title(route_direct)
                        .position(ll).visible(true);
   
                Marker marker = map.addMarker(markerOpt);
                marker.showInfoWindow();
                CameraUpdate update = CameraUpdateFactory.newLatLngZoom(ll, zoom);
                map.moveCamera(update);
                Toast.makeText(this, "inside getoLocation()!", Toast.LENGTH_SHORT)
                        .show();
   
            }
   
        }
   
        @Override
        public void onMapReady(GoogleMap arg0) {
            // TODO Auto-generated method stub
   
        }
   
        @Override
        protected void onNewIntent(Intent intent) {
            // TODO Auto-generated method stub
            super.onNewIntent(intent);
   
            @SuppressWarnings("unchecked")
            ArrayList<ItemDTO> list = (ArrayList<ItemDTO>) intent
                    .getSerializableExtra("list_data");
            for (ItemDTO itemDTO : list) {
                double latitude = itemDTO.getLatitude();
                double longitude = itemDTO.getLongitude();
                int route1 = itemDTO.getRoute();
                String route = Integer.toString(route1);
                String direction = itemDTO.getDirection();
                String route_dirc = route + ", " + direction;
   
                if (initMap()) {
                    Toast.makeText(this, "Ready to Map", Toast.LENGTH_SHORT).show();
                    gotoLocation(latitude, longitude, route_dirc);
   
                } else {
                    Toast.makeText(this, "Map not avialable", Toast.LENGTH_SHORT)
                            .show();
                }
   
            }
            Toast.makeText(this, "onNewIntent end!", Toast.LENGTH_SHORT).show();
        }
   
        @Override
        public void onBackPressed() {
            // TODO Auto-generated method stub
            super.onBackPressed();
        }
 
Ich glaube nicht das das an deinem Code liegt.

P.S.: Manchmal wird ohne "sch" geschrieben
 

Ähnliche Themen

S
  • skywalker22
Antworten
1
Aufrufe
154
swa00
swa00
S
Antworten
17
Aufrufe
529
jogimuc
J
S
Antworten
0
Aufrufe
577
Sergio13
S
Zurück
Oben Unten