问题
I faced with the problem - Google map is not shown in my Android Application. The App is based on O'Reilly Android Task manager Application.
Here is my layout
<com.google.android.maps.MapView
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
class="com.google.android.gms.maps.MapFragment"
android:clickable="true"
android:apiKey="AIzaSyALl1yI4zMyjnHoTSkgQjKQLE78uWZcAYk"
android:layout_below="@id/map_location_button"
android:layout_above="@+id/use_this_location_button"/>
my Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.khalilov.android.taskmanager"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.khalilov.android.taskmanager.permission.MAPS_RECEIVE"
android:protectionLevel="signature"></permission>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<application
android:allowBackup="true"
android:name=".TaskManagerApplication"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".ViewTasksActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AddTaskActivity" android:text="@string/app_name" />
<uses-library android:name="com.google.android.maps" />
<activity
android:name=".AddLocationMapActivity"
android:text="@string/add_location_to_task" />
<meta-data
android:name="com.google.android.v2.API_KEY"
android:value="AIzaSyALl1yI4zMyjnHoTSkgQjKQLE78uWZcAYk"/>
<service android:name=".services.MyService"/>
</application>
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="24" />
</manifest>
And Java code
public class AddLocationMapActivity extends MapActivity {
public static final String ADDRESS_RESULT = "address";
private EditText addressText;
private Button mapLocationButton;
private Button useLocationButton;
private MapView mapView;
private Address address;
private MyLocationOverlay myLocationOverlay;
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.add_location);
setUpView();
}
@Override
protected void onResume() {
super.onResume();
myLocationOverlay.enableMyLocation();
}
@Override
protected void onPause() {
super.onPause();
myLocationOverlay.disableMyLocation();
}
protected void mapCurrentAddress() {
//getting address from input
String addressString = addressText.getText().toString();
//geocoder - search for address to find a location
Geocoder g = new Geocoder(this);
List<Address> addresses;
try {
addresses = g.getFromLocationName(addressString, 1);
if(null != addresses && addresses.size()>0) {
address = addresses.get(0);
List<Overlay> mapOverlays = mapView.getOverlays();
AddressOverlay addressOverlay = new AddressOverlay(address);
mapOverlays.add(addressOverlay);
mapOverlays.add(myLocationOverlay);
mapView.invalidate();
final MapController mapController = mapView.getController();
mapController.animateTo(addressOverlay.getGeopoint(), new
Runnable() {
public void run() {
mapController.setZoom(12);
}
});
useLocationButton.setEnabled(true);
} else {
//Tell the user no results for that address
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void setUpView() {
addressText = (EditText)findViewById(R.id.task_address);
mapLocationButton = (Button)findViewById(R.id.map_location_button);
useLocationButton = (Button)findViewById(R.id.use_this_location_button);
mapView = (MapView)findViewById(R.id.map);
myLocationOverlay = new MyLocationOverlay(this, mapView);
mapView.getOverlays().add(myLocationOverlay);
mapView.invalidate();
useLocationButton.setEnabled(false);
mapView.setBuiltInZoomControls(true);
mapLocationButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mapCurrentAddress();
}
});
useLocationButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (null != address) {
Intent intent = new Intent();
intent.putExtra(ADDRESS_RESULT, address);
setResult(RESULT_OK, intent);
}finish();
}
});
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
@Override
//location of device
protected boolean isLocationDisplayed() {
return true;
}
}
log
It would be great if you help me to find the solution. Thanks
来源:https://stackoverflow.com/questions/44311847/google-map-is-not-shown-in-android-app