Android地图未显示在Android应用中

时间:2017-06-01 15:36:45

标签: java android google-maps taskmanager

我遇到了问题 - 我的Android应用中未显示Google地图。该应用程序基于O' Reilly Android任务管理器应用程序。

这是我的布局

<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"/>

我的清单

<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>

和Java代码

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

如果您帮我找到解决方案,那将会很棒。感谢

0 个答案:

没有答案