О приложении: - Это простое приложение, которое находит текущее местоположение пользователя.
Проблема: - Приложение отлично работает на эмуляторе, см. Изображение.
![enter image description here](https://i.stack.imgur.com/1UXPK.png)
Но в телефоне не отображается MapView. Пожалуйста, смотрите изображение.
![enter image description here](https://i.stack.imgur.com/3YoSS.png)
Скажите, пожалуйста, что не так с телефоном.В телефоне он просто загружает огромные (20 МБ) данные, но не отображает реальную карту.
Logcat im получаете -
10-31 16:44:45.994: E/MapActivity(3026): Couldn't get connection factory client
10-31 15:47:42.319: ERROR/MapView(1773): java.lang.IllegalStateException: Null Bitmap! "loading_tile"; if seen during a test, this usually means that the image file needs to be added to the test.config file
ФАЙЛ XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/myLocationText"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<com.google.android.maps.MapView
android:id="@+id/myMapView"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:clickable="true"
android:enabled="true"
android:apiKey="0bBgLl42nWwnTf983Y5VdIgfZI6mC7meL7Ms_qg"/>
</LinearLayout>
Код
public class WhereIam extends MapActivity {
MapController mapController;
MyPositionOverlay positionOverlay;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView myMapView=(MapView)findViewById(R.id.myMapView);
mapController=myMapView.getController();
myMapView.setSatellite(true);
myMapView.setStreetView(true);
myMapView.displayZoomControls(false);
myMapView.setBuiltInZoomControls(true);
mapController.setZoom(16);
positionOverlay = new MyPositionOverlay();
List<Overlay> overlays = myMapView.getOverlays();
overlays.add(positionOverlay);
LocationManager locationManager;
String context=Context.LOCATION_SERVICE;
locationManager=(LocationManager)getSystemService(context);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
String provider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(provider);
final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
updateWithNewLocation(location);
}
public void onProviderDisabled(String provider){
updateWithNewLocation(null);
}
public void onProviderEnabled(String provider){ }
public void onStatusChanged(String provider, int status,
Bundle extras){ }
};
updateWithNewLocation(location);
locationManager.requestLocationUpdates(provider, 2000, 10,
locationListener);
}
private void updateWithNewLocation(Location location) {
String latLongString;
TextView myLocationText;
String addressString ="No Address Found";
myLocationText=(TextView)findViewById(R.id.myLocationText);
if(location!=null) {
// Update the map location.
positionOverlay.setLocation(location);
Double geoLat = location.getLatitude()*1E6;
Double geoLng = location.getLongitude()*1E6;
GeoPoint point = new GeoPoint(geoLat.intValue(),
geoLng.intValue());
mapController.animateTo(point);
double lat=location.getLatitude();
double lng=location.getLongitude();
latLongString = "Lat:" + lat + "\nLong:" + lng;
Geocoder gc=new Geocoder(this, Locale.getDefault());
try {
List<Address> addressess= gc.getFromLocation(lat, lng, 1);
StringBuilder sb=new StringBuilder();
if(addressess.size()>0) {
Address address=addressess.get(0);
for(int i=0;i<address.getMaxAddressLineIndex();i++) {
sb.append(address.getAddressLine(i)).append("\n");
sb.append(address.getLocality()).append("\n");
sb.append(address.getPostalCode()).append("\n");
sb.append(address.getCountryName());
}
addressString = sb.toString();
}
}catch(IOException e) {}
}
else {
latLongString="No Found Location";
}
myLocationText.setText("Your current Location is \n"+latLongString+"\n"+addressString);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
Я только что создал один ключ API, следуя инструкциям goto-> cmd
, измените каталог на папку keytool
теперь запуститекоманда keytool -list -alias androiddebugkey -keystore "C: \ Users \ pc.android \ debug.keystore" -storepass android -keypass android
посмотреть изображение ![enter image description here](https://i.stack.imgur.com/1UXPK.png)
Теперь яПерейти на страницу регистрации. Я просто вставил MD5 в EditText и проверил согласие и нажал кнопку «Создать ключ», а затем появляется следующая страница, на которой показан ключ -
Теперь я вставил этот ключ в мой файл MapView Xml ..
Как вы можете видеть, приложение работает нормально в эмуляторе, но не в реальном телефоне.
Где я ошибаюсь и как мне сгенерировать второй ключ API для реального телефона?