0

我是 Android 开发的新手,我正在研究谷歌地图。我正在尝试使用纬度和经度导航到特定位置。我在清单文件中提供了所需的权限,但我无法导航,请帮助我。

主要活动,java

package com.examp.nowmap;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

@SuppressLint("NewApi")
public class MainActivity extends Activity {
static final LatLng GOA = new LatLng(15.193588,73.942366);
private GoogleMap mapn;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapn = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
    .getMap();
Marker hamburg = mapn.addMarker(new MarkerOptions().position(GOA)
    .title(LOCATION_SERVICE));

   mapn.moveCamera(CameraUpdateFactory.newLatLngZoom(GOA, BIND_ALLOW_OOM_MANAGEMENT));
   mapn.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);

}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
} 

清单.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.examp.nowmap"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />

<permission
    android:name="com.examp.nowmap.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

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

<uses-permission android:name="com.examp.nowmap.package.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission  android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.examp.nowmap.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyBZ2omuN7djk6R8eUNLkIrn13DEvnN-q58" />

</application>
</manifest>
4

1 回答 1

0

您没有权限:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

这是访问 Google 服务器所必需的,我不确定这是否会完全解决您的问题,但最好遵循 Android 的实际 Google API V2 教程。

单击此链接-> https://developers.google.com/maps/documentation/android/intro

这将帮助您确保一切设置正确。唯一值得注意的另一件事是确保您在真实设备上工作,因为谷歌地图无法在模拟器中工作。

于 2013-09-10T11:43:20.973 回答