我开发了一个应用程序来显示您所在地区的ATM机。它适用于我的Android手机,但当我尝试在我的Android可穿戴手表上启动时它会崩溃。错误"二进制XML文件行#2错误膨胀类片段"非常感谢任何帮助。
这是我的xml代码
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"/>
和我的活动:
public class MainActivity extends Activity {
private final String TAG = getClass().getSimpleName();
private GoogleMap mMap;
private String[] places;
private LocationManager locationManager;
private Location loc;
SharedPreferences sp;
static String distance;
public static final String PREF = "MyPrefs";
public static final String DISTANCE = "distance";
@Override
public void onResume() {
super.onResume();
sp = this.getSharedPreferences(PREF, Context.MODE_PRIVATE);
distance = sp.getString(DISTANCE, "1000");
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
currentLocation();
places=new String[1];
places[0]="ATM";
mMap.setMyLocationEnabled(true);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
private class GetPlaces extends AsyncTask<Void, Void, ArrayList<Place>> {
private ProgressDialog dialog;
private Context context;
private String places;
private double longitude;
private double latitude;
public GetPlaces(Context context, String places) {
this.context = context;
this.places = places;
}
@Override
protected void onPostExecute(ArrayList<Place> result) {
super.onPostExecute(result);
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location location = lm
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
longitude = location.getLongitude();
latitude = location.getLatitude();
if (dialog.isShowing()) {
dialog.dismiss();
}
for (int i = 0; i < result.size(); i++) {
mMap.addMarker(new MarkerOptions()
.title(result.get(i).getName())
.position(
new LatLng(result.get(i).getLatitude(), result
.get(i).getLongitude()))
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.pin))
.snippet(result.get(i).getVicinity()));
}
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(latitude, longitude)) // Sets the center of the map to
// Mountain View
.zoom(14) // Sets the zoom
.tilt(30) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
mMap.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
}
@Override
protected ArrayList<Place> doInBackground(Void... arg0) {
PlacesService service = new PlacesService(
"xxxxxxxxxxxxx");
ArrayList<Place> findPlaces = service.findPlaces(loc.getLatitude(),
loc.getLongitude(), places, distance);
for (int i = 0; i < findPlaces.size(); i++) {
Place placeDetail = findPlaces.get(i);
Log.e(TAG, "places : " + placeDetail.getName());
}
return findPlaces;
}
}
private void currentLocation() {
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
String provider = locationManager
.getBestProvider(new Criteria(), false);
Location location = locationManager.getLastKnownLocation(provider);
if (location == null) {
locationManager.requestLocationUpdates(provider, 0, 0, listener);
} else {
loc = location;
new GetPlaces(MainActivity.this, places[0].toLowerCase().replace(
"-", "_")).execute();
Log.e(TAG, "location : " + location);
}
}
private LocationListener listener = new LocationListener() {
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onLocationChanged(Location location) {
Log.e(TAG, "location update : " + location);
loc = location;
locationManager.removeUpdates(listener);
}
};
}
答案 0 :(得分:0)
很遗憾,Android Wear设备目前不支持MapFragment
和GoogleMap
(以及完整的Google Maps Android API)。