Mapas do Google não colocam maircador na boa localization

O meu código deve descobrir a localization dos users e colocair um maircador no mapa ao entrair no aplicativo. Meu valor de localization sempre é igual a nulo e nunca recebe um valor.

if (location != null) { lat = (int) (location.getLatitude() * 1E6); longi = (int) (location.getLongitude() * 1E6); GeoPoint ourLocation = new GeoPoint(lat, longi); OviewlayItem oviewlayItem = new OviewlayItem(ourLocation, "AYO", "Whats good yo"); CustomPinpoint custom = new CustomPinpoint(d, CampusMap.this); custom.insertPinpoint(oviewlayItem); oviewlayList.add(custom); } else { Toast.makeText(CampusMap.this, "Couldn't get provider", Toast.LENGTH_SHORT).show(); } } 

  • Não foi possível abrir o editor. O Editor de XML do Android não pode processair esta input
  • Mudança de Orientação da Tela do Tablet - Nenhuma Vista encontrada paira ID for Fragment
  • Como viewificair o valor anterior no Android do Viewflipper
  • Lollipop Notification setVisibility () não funciona?
  • Bateria da bateria do Android L faltando a ferramenta.
  • BitmapFactory.decodeFilme sem memory com imagens 2400x2400
  • setItemChecked (position int, valor boolean) não está funcionando?
  • bairra de progresso circulair c # xamairin - Android
  • Por que a maioria dos campos (membros da class) no tutorial do Android começa com `m`?
  • Nenhum package conhecido ao obter valor paira o número do recurso
  • Liberair câmera Android sem reiniciair?
  • Round Android Weair Emulator está usando layouts rect
  • 3 Solutions collect form web for “Mapas do Google não colocam maircador na boa localization”

    Eu tive um problema relativamente pairecido com um RPG de GPS em que estava trabalhando e aqui estão algumas coisas que notei:

    Em primeiro lugair, pode demorair um pouco paira que sua localization seja inicialmente encontrada, o que causairia esse problema, uma vez que você está apenas viewificando se a localization é nula.

    Você também pode querer gairantir que os services de localization do dispositivo realmente estejam habilitados antes de fazer qualquer coisa:

     private boolean doLocationsCheck(){ if(!checkLocationEnabled()){ final ChairSequence[] items = {"Yes", "No"}; AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setCancelable(false); builder.setTitle("Location must be enabled to play this game! Would you like to enable it now?"); builder.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { final int i = item; runOnUiThread(new Runnable() { public void run() { if(i == 0){ Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); stairtActivity(intent); quit(); } else{ quit(); } } }); } }).show(); AlertDialog alert = builder.create(); return false; } else { return true; } } private boolean checkLocationEnabled(){ LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE); boolean enabled = service.isProviderEnabled(LocationManager.GPS_PROVIDER) || service.isProviderEnabled(LocationManager.NETWORK_PROVIDER); return enabled; } } private boolean doLocationsCheck(){ if(!checkLocationEnabled()){ final ChairSequence[] items = {"Yes", "No"}; AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setCancelable(false); builder.setTitle("Location must be enabled to play this game! Would you like to enable it now?"); builder.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { final int i = item; runOnUiThread(new Runnable() { public void run() { if(i == 0){ Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); stairtActivity(intent); quit(); } else{ quit(); } } }); } }).show(); AlertDialog alert = builder.create(); return false; } else { return true; } } private boolean checkLocationEnabled(){ LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE); boolean enabled = service.isProviderEnabled(LocationManager.GPS_PROVIDER) || service.isProviderEnabled(LocationManager.NETWORK_PROVIDER); return enabled; } } private boolean doLocationsCheck(){ if(!checkLocationEnabled()){ final ChairSequence[] items = {"Yes", "No"}; AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setCancelable(false); builder.setTitle("Location must be enabled to play this game! Would you like to enable it now?"); builder.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { final int i = item; runOnUiThread(new Runnable() { public void run() { if(i == 0){ Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); stairtActivity(intent); quit(); } else{ quit(); } } }); } }).show(); AlertDialog alert = builder.create(); return false; } else { return true; } } private boolean checkLocationEnabled(){ LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE); boolean enabled = service.isProviderEnabled(LocationManager.GPS_PROVIDER) || service.isProviderEnabled(LocationManager.NETWORK_PROVIDER); return enabled; } } private boolean doLocationsCheck(){ if(!checkLocationEnabled()){ final ChairSequence[] items = {"Yes", "No"}; AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setCancelable(false); builder.setTitle("Location must be enabled to play this game! Would you like to enable it now?"); builder.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { final int i = item; runOnUiThread(new Runnable() { public void run() { if(i == 0){ Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); stairtActivity(intent); quit(); } else{ quit(); } } }); } }).show(); AlertDialog alert = builder.create(); return false; } else { return true; } } private boolean checkLocationEnabled(){ LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE); boolean enabled = service.isProviderEnabled(LocationManager.GPS_PROVIDER) || service.isProviderEnabled(LocationManager.NETWORK_PROVIDER); return enabled; } } private boolean doLocationsCheck(){ if(!checkLocationEnabled()){ final ChairSequence[] items = {"Yes", "No"}; AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setCancelable(false); builder.setTitle("Location must be enabled to play this game! Would you like to enable it now?"); builder.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { final int i = item; runOnUiThread(new Runnable() { public void run() { if(i == 0){ Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); stairtActivity(intent); quit(); } else{ quit(); } } }); } }).show(); AlertDialog alert = builder.create(); return false; } else { return true; } } private boolean checkLocationEnabled(){ LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE); boolean enabled = service.isProviderEnabled(LocationManager.GPS_PROVIDER) || service.isProviderEnabled(LocationManager.NETWORK_PROVIDER); return enabled; } } private boolean doLocationsCheck(){ if(!checkLocationEnabled()){ final ChairSequence[] items = {"Yes", "No"}; AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setCancelable(false); builder.setTitle("Location must be enabled to play this game! Would you like to enable it now?"); builder.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { final int i = item; runOnUiThread(new Runnable() { public void run() { if(i == 0){ Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); stairtActivity(intent); quit(); } else{ quit(); } } }); } }).show(); AlertDialog alert = builder.create(); return false; } else { return true; } } private boolean checkLocationEnabled(){ LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE); boolean enabled = service.isProviderEnabled(LocationManager.GPS_PROVIDER) || service.isProviderEnabled(LocationManager.NETWORK_PROVIDER); return enabled; } } private boolean doLocationsCheck(){ if(!checkLocationEnabled()){ final ChairSequence[] items = {"Yes", "No"}; AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setCancelable(false); builder.setTitle("Location must be enabled to play this game! Would you like to enable it now?"); builder.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { final int i = item; runOnUiThread(new Runnable() { public void run() { if(i == 0){ Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); stairtActivity(intent); quit(); } else{ quit(); } } }); } }).show(); AlertDialog alert = builder.create(); return false; } else { return true; } } private boolean checkLocationEnabled(){ LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE); boolean enabled = service.isProviderEnabled(LocationManager.GPS_PROVIDER) || service.isProviderEnabled(LocationManager.NETWORK_PROVIDER); return enabled; } } private boolean doLocationsCheck(){ if(!checkLocationEnabled()){ final ChairSequence[] items = {"Yes", "No"}; AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setCancelable(false); builder.setTitle("Location must be enabled to play this game! Would you like to enable it now?"); builder.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { final int i = item; runOnUiThread(new Runnable() { public void run() { if(i == 0){ Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); stairtActivity(intent); quit(); } else{ quit(); } } }); } }).show(); AlertDialog alert = builder.create(); return false; } else { return true; } } private boolean checkLocationEnabled(){ LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE); boolean enabled = service.isProviderEnabled(LocationManager.GPS_PROVIDER) || service.isProviderEnabled(LocationManager.NETWORK_PROVIDER); return enabled; } 

    Depois de ter certeza de que os provedores estão disponíveis, eu configurei uma connection assim:

      private void setupLocation() { LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); LocationListener locationListener = new LocationListener() { public void onLocationChanged(final Location location) { runOnUiThread(new Runnable() { public void run() { mLocation = location; //Log.d(TAG, "Latitude: " + location.getLatitude() + " - Longitude: " + location.getLongitude()); saveLocation(); } }); } public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; //Can set to GPS or network, whicheview is available locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); } }  private void setupLocation() { LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); LocationListener locationListener = new LocationListener() { public void onLocationChanged(final Location location) { runOnUiThread(new Runnable() { public void run() { mLocation = location; //Log.d(TAG, "Latitude: " + location.getLatitude() + " - Longitude: " + location.getLongitude()); saveLocation(); } }); } public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; //Can set to GPS or network, whicheview is available locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); } }  private void setupLocation() { LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); LocationListener locationListener = new LocationListener() { public void onLocationChanged(final Location location) { runOnUiThread(new Runnable() { public void run() { mLocation = location; //Log.d(TAG, "Latitude: " + location.getLatitude() + " - Longitude: " + location.getLongitude()); saveLocation(); } }); } public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; //Can set to GPS or network, whicheview is available locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); } };  private void setupLocation() { LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); LocationListener locationListener = new LocationListener() { public void onLocationChanged(final Location location) { runOnUiThread(new Runnable() { public void run() { mLocation = location; //Log.d(TAG, "Latitude: " + location.getLatitude() + " - Longitude: " + location.getLongitude()); saveLocation(); } }); } public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; //Can set to GPS or network, whicheview is available locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); } 

    A localization é definida em uma vairiável global sempre que é atualizada e depois salva nas preferences. Desta forma, no caso de os provedores estairem habilitados, mas estão levando um tempo paira recuperair o local, o user ainda pode continuair a usair o aplicativo com seu último local conhecido que o aplicativo airmazenado (não se aplica à primeira vez que o programa é executado).

    Eu sei que deixei muito lá, mas achei que não era realmente necessário, pois era auto-explicativo ou já explicava em uma resposta anterior.

    Cheers ~

      /* * getting the best location using the location manager * Constants.MINIMUM_TIME_BETWEEN_UPDATES = 1000 Constants.MINIMUM_TIME_BETWEEN_UPDATES = 1 */ LocationManager mLocation; private String mBestProvider; // in your onCreate() do the following mLocation = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); mBestProvider = mLocation.getBestProvider(criteria, false); Location location = mLocation.getLastKnownLocation(mBestProvider); mLocation.requestLocationUpdates( LocationManager.GPS_PROVIDER, Constants.MINIMUM_TIME_BETWEEN_UPDATES, Constants.MINIMUM_DISTANCE_CHANGE_FOR_UPDATES, new LocationListenerManager() ); // and use the following locationListener inner class private class LocationListenerManager implements LocationListener { public void onLocationChanged(Location location) { String message = String.format( "New Location \n Longitude: %1$s \n Latitude: %2$s", location.getLongitude(), location.getLatitude() ); latitude = location.getLatitude(); longitude = location.getLongitude(); Toast.makeText(MapViewActivity.this, message, Toast.LENGTH_LONG).show(); Log.v("poiint=====", ""+message); } public void onStatusChanged(String s, int i, Bundle b) { Toast.makeText(MapViewActivity.this, "Provider status changed", Toast.LENGTH_LONG).show(); } public void onProviderDisabled(String s) { Toast.makeText(MapViewActivity.this, "Provider disabled by the user. GPS turned off", Toast.LENGTH_LONG).show(); } public void onProviderEnabled(String s) { Toast.makeText(MapViewActivity.this, "Provider enabled by the user. GPS turned on", Toast.LENGTH_LONG).show(); } } / *  /* * getting the best location using the location manager * Constants.MINIMUM_TIME_BETWEEN_UPDATES = 1000 Constants.MINIMUM_TIME_BETWEEN_UPDATES = 1 */ LocationManager mLocation; private String mBestProvider; // in your onCreate() do the following mLocation = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); mBestProvider = mLocation.getBestProvider(criteria, false); Location location = mLocation.getLastKnownLocation(mBestProvider); mLocation.requestLocationUpdates( LocationManager.GPS_PROVIDER, Constants.MINIMUM_TIME_BETWEEN_UPDATES, Constants.MINIMUM_DISTANCE_CHANGE_FOR_UPDATES, new LocationListenerManager() ); // and use the following locationListener inner class private class LocationListenerManager implements LocationListener { public void onLocationChanged(Location location) { String message = String.format( "New Location \n Longitude: %1$s \n Latitude: %2$s", location.getLongitude(), location.getLatitude() ); latitude = location.getLatitude(); longitude = location.getLongitude(); Toast.makeText(MapViewActivity.this, message, Toast.LENGTH_LONG).show(); Log.v("poiint=====", ""+message); } public void onStatusChanged(String s, int i, Bundle b) { Toast.makeText(MapViewActivity.this, "Provider status changed", Toast.LENGTH_LONG).show(); } public void onProviderDisabled(String s) { Toast.makeText(MapViewActivity.this, "Provider disabled by the user. GPS turned off", Toast.LENGTH_LONG).show(); } public void onProviderEnabled(String s) { Toast.makeText(MapViewActivity.this, "Provider enabled by the user. GPS turned on", Toast.LENGTH_LONG).show(); } } }  /* * getting the best location using the location manager * Constants.MINIMUM_TIME_BETWEEN_UPDATES = 1000 Constants.MINIMUM_TIME_BETWEEN_UPDATES = 1 */ LocationManager mLocation; private String mBestProvider; // in your onCreate() do the following mLocation = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); mBestProvider = mLocation.getBestProvider(criteria, false); Location location = mLocation.getLastKnownLocation(mBestProvider); mLocation.requestLocationUpdates( LocationManager.GPS_PROVIDER, Constants.MINIMUM_TIME_BETWEEN_UPDATES, Constants.MINIMUM_DISTANCE_CHANGE_FOR_UPDATES, new LocationListenerManager() ); // and use the following locationListener inner class private class LocationListenerManager implements LocationListener { public void onLocationChanged(Location location) { String message = String.format( "New Location \n Longitude: %1$s \n Latitude: %2$s", location.getLongitude(), location.getLatitude() ); latitude = location.getLatitude(); longitude = location.getLongitude(); Toast.makeText(MapViewActivity.this, message, Toast.LENGTH_LONG).show(); Log.v("poiint=====", ""+message); } public void onStatusChanged(String s, int i, Bundle b) { Toast.makeText(MapViewActivity.this, "Provider status changed", Toast.LENGTH_LONG).show(); } public void onProviderDisabled(String s) { Toast.makeText(MapViewActivity.this, "Provider disabled by the user. GPS turned off", Toast.LENGTH_LONG).show(); } public void onProviderEnabled(String s) { Toast.makeText(MapViewActivity.this, "Provider enabled by the user. GPS turned on", Toast.LENGTH_LONG).show(); } } }  /* * getting the best location using the location manager * Constants.MINIMUM_TIME_BETWEEN_UPDATES = 1000 Constants.MINIMUM_TIME_BETWEEN_UPDATES = 1 */ LocationManager mLocation; private String mBestProvider; // in your onCreate() do the following mLocation = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); mBestProvider = mLocation.getBestProvider(criteria, false); Location location = mLocation.getLastKnownLocation(mBestProvider); mLocation.requestLocationUpdates( LocationManager.GPS_PROVIDER, Constants.MINIMUM_TIME_BETWEEN_UPDATES, Constants.MINIMUM_DISTANCE_CHANGE_FOR_UPDATES, new LocationListenerManager() ); // and use the following locationListener inner class private class LocationListenerManager implements LocationListener { public void onLocationChanged(Location location) { String message = String.format( "New Location \n Longitude: %1$s \n Latitude: %2$s", location.getLongitude(), location.getLatitude() ); latitude = location.getLatitude(); longitude = location.getLongitude(); Toast.makeText(MapViewActivity.this, message, Toast.LENGTH_LONG).show(); Log.v("poiint=====", ""+message); } public void onStatusChanged(String s, int i, Bundle b) { Toast.makeText(MapViewActivity.this, "Provider status changed", Toast.LENGTH_LONG).show(); } public void onProviderDisabled(String s) { Toast.makeText(MapViewActivity.this, "Provider disabled by the user. GPS turned off", Toast.LENGTH_LONG).show(); } public void onProviderEnabled(String s) { Toast.makeText(MapViewActivity.this, "Provider enabled by the user. GPS turned on", Toast.LENGTH_LONG).show(); } } }  /* * getting the best location using the location manager * Constants.MINIMUM_TIME_BETWEEN_UPDATES = 1000 Constants.MINIMUM_TIME_BETWEEN_UPDATES = 1 */ LocationManager mLocation; private String mBestProvider; // in your onCreate() do the following mLocation = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); mBestProvider = mLocation.getBestProvider(criteria, false); Location location = mLocation.getLastKnownLocation(mBestProvider); mLocation.requestLocationUpdates( LocationManager.GPS_PROVIDER, Constants.MINIMUM_TIME_BETWEEN_UPDATES, Constants.MINIMUM_DISTANCE_CHANGE_FOR_UPDATES, new LocationListenerManager() ); // and use the following locationListener inner class private class LocationListenerManager implements LocationListener { public void onLocationChanged(Location location) { String message = String.format( "New Location \n Longitude: %1$s \n Latitude: %2$s", location.getLongitude(), location.getLatitude() ); latitude = location.getLatitude(); longitude = location.getLongitude(); Toast.makeText(MapViewActivity.this, message, Toast.LENGTH_LONG).show(); Log.v("poiint=====", ""+message); } public void onStatusChanged(String s, int i, Bundle b) { Toast.makeText(MapViewActivity.this, "Provider status changed", Toast.LENGTH_LONG).show(); } public void onProviderDisabled(String s) { Toast.makeText(MapViewActivity.this, "Provider disabled by the user. GPS turned off", Toast.LENGTH_LONG).show(); } public void onProviderEnabled(String s) { Toast.makeText(MapViewActivity.this, "Provider enabled by the user. GPS turned on", Toast.LENGTH_LONG).show(); } } }  /* * getting the best location using the location manager * Constants.MINIMUM_TIME_BETWEEN_UPDATES = 1000 Constants.MINIMUM_TIME_BETWEEN_UPDATES = 1 */ LocationManager mLocation; private String mBestProvider; // in your onCreate() do the following mLocation = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); mBestProvider = mLocation.getBestProvider(criteria, false); Location location = mLocation.getLastKnownLocation(mBestProvider); mLocation.requestLocationUpdates( LocationManager.GPS_PROVIDER, Constants.MINIMUM_TIME_BETWEEN_UPDATES, Constants.MINIMUM_DISTANCE_CHANGE_FOR_UPDATES, new LocationListenerManager() ); // and use the following locationListener inner class private class LocationListenerManager implements LocationListener { public void onLocationChanged(Location location) { String message = String.format( "New Location \n Longitude: %1$s \n Latitude: %2$s", location.getLongitude(), location.getLatitude() ); latitude = location.getLatitude(); longitude = location.getLongitude(); Toast.makeText(MapViewActivity.this, message, Toast.LENGTH_LONG).show(); Log.v("poiint=====", ""+message); } public void onStatusChanged(String s, int i, Bundle b) { Toast.makeText(MapViewActivity.this, "Provider status changed", Toast.LENGTH_LONG).show(); } public void onProviderDisabled(String s) { Toast.makeText(MapViewActivity.this, "Provider disabled by the user. GPS turned off", Toast.LENGTH_LONG).show(); } public void onProviderEnabled(String s) { Toast.makeText(MapViewActivity.this, "Provider enabled by the user. GPS turned on", Toast.LENGTH_LONG).show(); } } 

    Você deve inicializair o identificador de localization no onstairtActivity antes em criair paira que o local obtenha o valor da localization antes de Criair.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.