Hallo,
Mein Problem: Ich gebe Location-Daten vor und will mir die zugehörige Google-Map anzeigen lassen. Das Ganze unter dem Emulator mit Eclipse.
Hier nochmal einen Versuch mit gestraffter Darstellung und nun die einzelnen Teile.
Zum Zeitpunkt der LogCat-Ausgaben habe ich noch keinerlei User-Aktionen (Buttons) ausgeführt.
LogCat
LogCat:
04-16 12:40:45.440: I/**** LocationDemo2(1062): onStart(2)
04-16 12:40:45.470: I/**** LocationDemo2(1062): onResume()
04-16 12:40:45.851: I/MapActivity(1062): Handling network change notification:CONNECTED
04-16 12:40:45.881: E/MapActivity(1062): Couldn't get connection factory client
04-16 12:40:46.991: W/System.err(1062): IOException processing: 26
04-16 12:40:47.021: W/System.err(1062): java.io.IOException: Server returned: 3
04-16 12:40:47.021: W/System.err(1062): at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
04-16 12:40:47.031: W/System.err(1062): at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
04-16 12:40:47.031: W/System.err(1062): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
04-16 12:40:47.041: W/System.err(1062): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
04-16 12:40:47.041: W/System.err(1062): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
04-16 12:40:47.051: W/System.err(1062): at java.lang.Thread.run(Thread.java:856)
04-16 12:40:47.411: W/System.err(1062): IOException processing: 26
04-16 12:40:47.411: W/System.err(1062): java.io.IOException: Server returned: 3
... wiederholt sich mehrfach
Manifest und Layout:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.thomaskuenneth.locationdemo2" android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="9" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<uses-library android:name="com.google.android.maps" />
<activity android:name=".LocationDemo2" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyB4-pXW5FYzfXGB9FKnO8U1WTYYiAL_a1E"/>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="6dp"
>
<Button
android:id="@+id/button"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:text="@string/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.10"
/>
<Button
android:id="@+id/buttonSchochwitz"
android:text="@string/buttonSchochwitz"
android:layout_toRightOf="@id/button"
android:layout_alignTop="@id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.10"
/>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_above="@id/button"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.90"
android:clickable="true"
android:apiKey="meinAPIKey"
/>
</RelativeLayout>
Codeausschnitt:
package com.thomaskuenneth.locationdemo2;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import java.util.List;
import java.util.StringTokenizer;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
public class LocationDemo2 extends MapActivity {
private static final String TAG = "**** "+LocationDemo2.class.getSimpleName();
private LocationManager manager;
private LocationListener listener;
private MapController mapController;
MapView mapView;
GeoPoint geoPoint;
GeoPoint lastpoint;
JSONArray jarr;
boolean network = false; //Koordinaten übers Netzwerk (false: GPS)
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
showCurrentLocation();
}
});
Button buttonSchochwitz = (Button) findViewById(R.id.buttonSchochwitz);
buttonSchochwitz.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
double d1 = Location.convert("049:27");//"051:31:47");
double d2 = Location.convert("011:05");//"011:44:46");
//Gasthaus Bärenbichl, Tabelle twhk_googlemaps_static,float-Felder lat,lng
// d1=47.391308;
// d2=12.411795;
geoPoint = new GeoPoint((int)(d1*1E6), (int)(d2*1E6)); //lat,lon
Location loc;
if (network)
loc=new Location(LocationManager.NETWORK_PROVIDER);
else
loc=new Location(LocationManager.GPS_PROVIDER);
loc.setLatitude(d1);
loc.setLongitude(d2);
String zo = Location.convert(loc.getLongitude(),Location.FORMAT_SECONDS);
String za = Location.convert(loc.getLatitude(),Location.FORMAT_SECONDS);
String message = String.format(
"Current Location \n Longitude: %1$s \n Latitude: %2$s",zo,za
);
Toast.makeText(LocationDemo2.this, message, Toast.LENGTH_LONG).show();
mapController.setCenter(geoPoint);
mapController.animateTo(geoPoint);
mapView.invalidate();
}
});
// Location Manager ermitteln
manager = (LocationManager) getSystemService(LOCATION_SERVICE);
// LocationListener definieren
listener = new LocationListener() {
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
String s = "";
switch (status) {
case LocationProvider.AVAILABLE:
s="AVAILABLE"; break;
case LocationProvider.TEMPORARILY_UNAVAILABLE:
s="TEMPORARILY_UNAVAILABLE";break;
case LocationProvider.OUT_OF_SERVICE:
s="OUT_OF_SERVICE";
}
Log.i(TAG, "onStatusChanged(),"+provider+":"+s);
}
@Override
public void onProviderEnabled(String provider) {
Log.i(TAG, "onProviderEnabled()");
}
@Override
public void onProviderDisabled(String provider) {
Log.i(TAG, "onProviderDisabled()");
}
@Override
public void onLocationChanged(Location location) {
Log.i(TAG, "onLocationChanged(1)");
Toast.makeText(LocationDemo2.this, "**** onLocationChanged()",
Toast.LENGTH_SHORT).show();
// Koordinaten umwandeln
int lat = (int) (location.getLatitude() * 1E6);
int lng = (int) (location.getLongitude() * 1E6);
geoPoint = new GeoPoint(lat, lng);
mapController.setCenter(geoPoint);
mapController.animateTo(geoPoint);
// mapController.zoomToSpan(lat, lng);
}
}; //Ende LocationListener
// Zoom aktivieren
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
// MapController ermitteln
mapController = mapView.getController();
//Ermittlung des Abstands: aktuelle Location -> Fixpunkt (aus JSON-Datei)
// getJson(); //zum Einlesen der JSON-Datei
} //Ende onCreate
@Override
protected void onStart() {
super.onStart();
// Log.i(TAG, "onStart(1)");
if (network)
manager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,3000, 0, listener);
else
manager.requestLocationUpdates(LocationManager.GPS_PROVIDER,3000, 0, listener);
Log.i(TAG, "onStart(2)");
// getAllPrv();
//fügt der MapView neues Overlay (zum zeichnen der 'current location') hinzu
List<Overlay> overlays = mapView.getOverlays();
// overlays.clear();
overlays.add(new MyOverlay());
}
protected void onResume() {
super.onResume();
Log.i(TAG, "onResume()");
Toast.makeText(LocationDemo2.this, "**** onResume", Toast.LENGTH_LONG).show();
}
Ich hoffe auf Hinweise.
Gruß Wicki
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.