0

在我的 xml 我有这个

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/contactusscene"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ContactUsScene" >

<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="400dp"
    class="com.google.android.gms.maps.SupportMapFragment" />

</RelativeLayout>

在这样的代码中

mMap = mapfm.getMap();
mMap.setTrafficEnabled(true);

UiSettings settings = mMap.getUiSettings();
mMap.animateCamera(CameraUpdateFactory
            .newCameraPosition(new CameraPosition(new LatLng(10.23454,
                    123.5543534), 13.5f, 30f, 112.5f)));
    mMap.setTrafficEnabled(true);
    settings.setAllGesturesEnabled(true);
    settings.setCompassEnabled(true);
    settings.setMyLocationButtonEnabled(true);
    settings.setRotateGesturesEnabled(true);
    settings.setScrollGesturesEnabled(true);
    settings.setTiltGesturesEnabled(true);
    settings.setZoomControlsEnabled(true);
    settings.setZoomGesturesEnabled(true);

在日志中,它一直在运行,并且无法显示位置和地图。它只有银色。

05-25 20:50:33.689: E/Adreno200-EGLSUB(11275): Enter: GetBackBuffer(), surface: 0x3ef488, bufid: 0
05-25 20:50:33.689: E/Adreno200-EGLSUB(11275): Return: GetBackBuffer(), TRUE
05-25 20:50:33.709: E/Adreno200-EGLSUB(11275): Enter: GetBackBuffer(), surface: 0x3ef488, bufid: 1
05-25 20:50:33.709: E/Adreno200-EGLSUB(11275): Return: GetBackBuffer(), TRUE
4

3 回答 3

0

在您的中添加以下权限AndroidManifest.xml

<permission 
    android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE" 
    android:protectionLevel="signature"></permission>
<uses-permission 
    android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE"/>
<uses-permission 
    android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission 
    android:name="android.permission.INTERNET"/>
<uses-permission 
    android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission 
    android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission 
    android:name="android.permission.ACCESS_FINE_LOCATION"/>

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>

<application>标签内添加以下代码。用您的 API 密钥替换API密钥。

  <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value=" API Key"/>

扩展您的 Activity 从FragmentActivity.

然后使用下面的代码。

FragmentManager myFragmentManager = getSupportFragmentManager();

SupportMapFragment mySupportMapFragment = (SupportMapFragment) myFragmentManager
                .findFragmentById(R.id.map);

GoogleMap myMap = mySupportMapFragment.getMap();

然后用myMap对象做你的东西。

于 2013-05-25T13:07:34.190 回答
0

用户这样:

在你的 layout.xml

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

你的活动:

public class showMaps extends AbstractMapActivity {

    private GoogleMap map;   


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        if (readyToGo()) {
            setContentView(R.layout.showmaps);

            SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.map);    
            map = mapFrag.getMap();   
        }
    }

}

这是AbstractMapActivity.java在您的代码中添加此文件:

如果需要,这里是完整代码的使用。

确保您已添加所有必需的权限、openGL、MAP API 密钥(您自己的密钥)。

有关地图的更多详细信息android-manifest

于 2013-05-25T13:25:42.190 回答
0

尝试这个:

int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
        if(status == ConnectionResult.SUCCESS) {
                    // what you want to do
            Toast.makeText(getApplicationContext(), "Hello", Toast.LENGTH_SHORT).show();
        }

那么你必须添加这个:

if (googleMap == null) {
            // Try to obtain the map from the SupportMapFragment.
            googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                    .getMap();
            // Check if we were successful in obtaining the map.
            googleMap.setMyLocationEnabled(true);
            googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);       

            if (googleMap != null) {

                UiSettings settings = googleMap.getUiSettings();

            settings.setZoomControlsEnabled(true);
            settings.setCompassEnabled(true);
            settings.setTiltGesturesEnabled(false);

             settings.setMyLocationButtonEnabled(true);

            }
        }

笔记:

SupportMapFragment mMap;
GoogleMap googleMap;

希望对你有帮助。

于 2013-05-25T13:33:21.023 回答