我正在开展一个涉及兴趣点的项目"定位。我有一个生成的Google Maps API v2密钥,我已经为AndroidManifest添加了所有适当的权限(正如您将在下面看到的那样),并且所有内容都会编译......除了地图本身!这里有一个标记,可以显示您当前的位置以及GPS坐标,但不会显示地图,不用说这是必不可少的。此外,没有运行时错误,除了LogCat在点&#34处说;有太多的输出要处理"。任何帮助将不胜感激。
Android Manifest
package="com.example.kavin_000.travelapplication" >
<!-- suppress AndroidDomInspection -->
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="19" />
<permission
android:name="com.example.kavin_000.travelapplication.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.kavin_000.travelapplication.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" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="@drawable/nyit_icon"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".ow_main_page"
android:label="@string/app_name" >
</activity>
<activity
android:name=".manhattan_main_page"
android:label="@string/title_activity_manhattan_main_page" >
</activity>
<activity
android:name=".main_page"
android:label="Travel Application" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ow_campus_points_of_interest"
android:label="@string/title_activity_ow_campus_points_of_interest" >
</activity>
<activity
android:name=".manhattan_campus_points_of_interest"
android:label="@string/title_activity_manhattan_campus_points_of_interest" >
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="MY_KEY" />
</application>
</manifest>
布局XML文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".ow_main_page"
android:background="#ffffb502">
<fragment
android:id="@+id/googleMap"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_above="@+id/latlongLocation" />
<TextView
android:id="@+id/latlongLocation"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:layout_alignParentBottom="true"
android:background="#ff058fff"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:textColor="#ffffffff"
android:paddingLeft="5dp"
android:paddingRight="5dp" />
</RelativeLayout>
有问题的Java类
package com.example.kavin_000.travelapplication;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.TextView;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class ow_campus_points_of_interest extends FragmentActivity implements LocationListener {
GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//show error dialog if GooglePlayServices not available
if (!isGooglePlayServicesAvailable()) {
finish();
}
setContentView(R.layout.activity_ow_campus_points_of_interest);
SupportMapFragment supportMapFragment =
(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.googleMap);
googleMap = supportMapFragment.getMap();
googleMap.setMyLocationEnabled(true);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String bestProvider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(bestProvider);
if (location != null) {
onLocationChanged(location);
}
locationManager.requestLocationUpdates(bestProvider, 20000, 0, this);
}
@Override
public void onLocationChanged(Location location) {
TextView locationTv = (TextView) findViewById(R.id.latlongLocation);
double latitude = location.getLatitude();
double longitude = location.getLongitude();
LatLng latLng = new LatLng(latitude, longitude);
googleMap.addMarker(new MarkerOptions().position(latLng));
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
locationTv.setText("Latitude:" + latitude + ", Longitude:" + longitude);
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
private boolean isGooglePlayServicesAvailable() {
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (ConnectionResult.SUCCESS == status) {
return true;
} else {
GooglePlayServicesUtil.getErrorDialog(status, this, 0).show();
return false;
}
}
}
答案 0 :(得分:1)
听起来您在Google App Engine上的授权可能存在问题。您确定使用 debug.keystore 中的SHA1指纹而不是发布密钥库中的SHA1指纹吗?此外,请确保将;com.example.kavin_000.travelapplication
附加到SHA1指纹的末尾。
如果您尚未将SHA1指纹添加到授权应用程序列表中,那就是问题所在。可以通过查找debug.keystore
文件(根据您的操作系统在Google上搜索)并运行以下命令来完成此操作:
keytool -list -v -keystore debug.keystore