这是一种处理我的代码中的新位置的方法,我是否应该在其他地方添加标记infoWindow,以便在加载活动时显示它,或者是否存在一些简单的错误?谢谢!
private void handleNewLocation(Location location) {
final double latitude = location.getLatitude();
final double longitude = location.getLongitude();
LatLng latLng = new LatLng(latitude,longitude);
Marker marker = mMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.map_marker_mini)));
marker.showInfoWindow();
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(15));
mMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker marker) {
View v = getLayoutInflater().inflate(R.layout.info_window, null);
Geocoder geocoder = new Geocoder(getApplicationContext());
List<Address> currentLocation = null;
try {
currentLocation = geocoder.getFromLocation(latitude, longitude, 1);
} catch (Exception ex) {
ex.printStackTrace();
}
String address = currentLocation.get(0).getAddressLine(0);
String city = currentLocation.get(0).getLocality();
String postal = currentLocation.get(0).getPostalCode();
String country = currentLocation.get(0).getCountryCode();
TextView Address = (TextView) v.findViewById(R.id.txtAddress);
Address.setText(address + ", " + city + ",\n " + postal + ", " + country);
return v;
}
@Override
public View getInfoContents(Marker marker) {
return null;
}
});
}