goodtimes922
@goodtimes922

В чем может быть проблема при запуске карты?

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);

        myDBHelper= new DBHelper(this);

        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);

        Cursor cursor_for_test= myDBHelper.getAll();
        if(cursor_for_test.getCount()==0) {
            new Thread(new Runnable() {
                public void run() {
                    Log.d("TESTING", "cursor_for_test");
                    parsingJSON();
                }
            }).start();
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        switch (requestCode){
            case 10:
                if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                        requestPermissions(new String[]{android.Manifest.permission.ACCESS_COARSE_LOCATION, android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.INTERNET}
                                ,10);
                        locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
                        locationManager.requestLocationUpdates("gps", 5000, 0, listener);
                        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, listener);
                    }
                    return;
                }
                break;
            default:
                break;
        }
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
        Log.d("TESTING","onMapReady");
        if(locationManager!=null) {
            Location lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            if (lastKnownLocation != null && latitude != 0.0 && longitude != 0.0) {
                latitude = lastKnownLocation.getLatitude();
                longitude = lastKnownLocation.getLongitude();
            }

            latLng = new LatLng(latitude, longitude);
            marker = mMap.addMarker(new MarkerOptions().position(latLng).title("My position"));

            mMap.animateCamera(CameraUpdateFactory.zoomTo(7.0f));
            mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
            googleMap.getUiSettings().setCompassEnabled(true);

            circleOptions = new CircleOptions()
                    .center(latLng)
                    .radius(radius)
                    .strokeColor(Color.RED);
            circle = mMap.addCircle(circleOptions);
            circle.setVisible(true);

            currentZoomLevel = getZoomLevel(circle);
            animateZomm = currentZoomLevel;
            mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, animateZomm));
            mMap.animateCamera(CameraUpdateFactory.zoomTo(currentZoomLevel), 2000, null);
            puttingMarkers();
        }
    }

    public String loadJson(){
        String json = null;
        byte[] buffer = null;
        InputStream is;
        try {
            is = getAssets().open("json.json");
            int size = is.available();
            buffer = new byte[size];
            is.read(buffer);
            is.close();
            json = new String(buffer, "UTF-8");
        } catch (IOException e) {
            e.printStackTrace();
        }

        return json;
    }

    public void parsingJSON(){
        try {
            JSONArray jsonArray= new JSONArray(loadJson());
            for(int i=0; i<jsonArray.length();i++){
                JSONObject c = jsonArray.getJSONObject(i);
                String CommonName = c.getString("CommonName");
                String Category = c.getString("Category");
                Category= parseString(Category);

                JSONObject obj  = c.getJSONObject("geoData");
                String coordinates = obj.getString("coordinates");
                coordinates= coordinates.substring(1);
                coordinates= coordinates.substring(0, coordinates.length()-1);;
                Log.d("TESTING","coordinates= "+coordinates);
                db = myDBHelper.getWritableDatabase();
                latitude_for_insert=coordinates.substring(coordinates.indexOf(","));
                longitude_for_insert=coordinates.substring(0,coordinates.indexOf(","));
                coordinates=latitude_for_insert+","+longitude_for_insert;
                coordinates= coordinates.substring(1);
                Log.d("TESTING","coordinates_new= "+coordinates);
                myDBHelper.insert(CommonName,Category,coordinates);
            }
        } catch (JSONException e) {
            Log.d("TESTING","JSONException= "+e);
            e.printStackTrace();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                requestPermissions(new String[]{android.Manifest.permission.ACCESS_COARSE_LOCATION,android.Manifest.permission.ACCESS_FINE_LOCATION,android.Manifest.permission.INTERNET}
                        ,10);
            }
            return;
        }
        else{
            locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
            locationManager.requestLocationUpdates("gps", 5000, 1, listener);
            locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 1, listener);
        }
    }
    @Override
    protected void onPause() {
        if(locationManager!=null){
            locationManager.removeUpdates(listener);
        }
        super.onPause();
    }
}


Приложение открывается, карта грузится, но по координатам 0.0, 0.0 . После нахождения координат местоположения карта должна обновиться, но не обновляется.

d7cbe36684a8470badf6c7d14090e334.png
  • Вопрос задан
  • 239 просмотров
Решения вопроса 1
goodtimes922
@goodtimes922 Автор вопроса
Эмулятор не поддерживает GPS
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 1
Извините, но все штатные экстрасенсы в отпуске.
Вы бы хоть какой-нибудь код прикрепили, чтобы нормальный ответ получить, а не результат "гадания по фотографии".
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы