Android: как открыть карту Google? - PullRequest
0 голосов
/ 17 мая 2011

У меня есть действие, которое расширяет MapActivity.После выполнения действия на эмуляторе должна появиться карта Google.Как я могу это сделать?

Ответы [ 4 ]

3 голосов
/ 17 мая 2011

http://www.vogella.de/articles/AndroidLocationAPI/article.html#overview_maps
Эта ссылка получила то, что вам нужно.
я это сделал. и у меня это тоже работает ..
Просто перейдите к 4-й теме из указателя. (Google Maps)

Спасибо

ОБНОВЛЕНИЕ:
Файл манифеста:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.vogella.android.locationapi.maps" android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".ShowMap" android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <uses-library android:required="true" android:name="com.google.android.maps"></uses-library>

</application>

XML LayoutFile:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainlayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<com.google.android.maps.MapView
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:apiKey="Your Maps API Key"
/>

</RelativeLayout>  

Активность:

import com.google.android.maps.GeoPoint; импорт com.google.android.maps.MapActivity; импорт com.google.android.maps.MapController; импорт com.google.android.maps.MapView;

открытый класс ShowMap расширяет MapActivity {

private MapController mapController;
private MapView mapView;
private LocationManager locationManager;

public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.main); // bind the layout to the activity

    // create a map view
    RelativeLayout linearLayout = (RelativeLayout) findViewById(R.id.mainlayout);
    mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);
    mapView.setStreetView(true);
    mapController = mapView.getController();
    mapController.setZoom(14); // Zoon 1 is world view
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
            0, new GeoUpdateHandler());
}

@Override
protected boolean isRouteDisplayed() {
    return false;
}

public class GeoUpdateHandler implements LocationListener {

    @Override
    public void onLocationChanged(Location location) {
        int lat = (int) (location.getLatitude() * 1E6);
        int lng = (int) (location.getLongitude() * 1E6);
        GeoPoint point = new GeoPoint(lat, lng);
        mapController.animateTo(point); //  mapController.setCenter(point);
    }

    @Override
    public void onProviderDisabled(String provider) {
    }

    @Override
    public void onProviderEnabled(String provider) {
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
    }
}
}
2 голосов
/ 17 мая 2011

для запуска просмотра карты, затем перейдите по ссылке mapview

1 голос
/ 17 мая 2011

Вы можете ссылаться на эту ссылку, http://developer.android.com/resources/tutorials/views/hello-mapview.html

Проверьте, правильно ли вы предоставили свой ключ API карты. Эта ссылка помогла мне отобразить карту с моим текущим местоположением.

1 голос
/ 17 мая 2011

Вы должны зарегистрироваться здесь , а затем вставить код, указанный в вашем макете, следующим образом:

<com.google.android.maps.MapView
    android:id="@+id/map_map"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:apiKey="***************************************"
/>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...