谷歌地图完美呈现,googleplayservices也存在, 但我的右上角的位置按钮不能在谷歌地图api v2我的wifi和gps两个都在.Kindly帮助。 我在手机上测试它。 我不知道为什么它不起作用
mainActivity.java
package com.example.mapexample;
import android.app.Dialog;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.util.Log;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
public class MainActivity extends FragmentActivity{
final int RQS_GooglePlayServices = 1;
private GoogleMap myMap;
private LocationManager locationManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Do a null check to confirm that we have not already instantiated the map.
if (myMap == null) {
myMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
// Check if we were successful in obtaining the map.
if (myMap != null) {
// The Map is verified. It is now safe to manipulate the map.
setUpMap();
}
}
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if (resultCode == ConnectionResult.SUCCESS){
Toast.makeText(getApplicationContext(),
"isGooglePlayServicesAvailable SUCCESS",
Toast.LENGTH_LONG).show();
}else{
GooglePlayServicesUtil.getErrorDialog(resultCode, this, RQS_GooglePlayServices);
}
}
private void setUpMap(){
myMap.setMyLocationEnabled(true);
}
}
mainifest文件在这里具有适当的权限。 的 mainfest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mapexample"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.example.mapexample.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.mapexample.permission.MAPS_RECEIVE" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-library
android:name="com.google.android.maps"
android:required="true" />
<activity
android:name="com.example.mapexample.MainMenuActivity"
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="com.example.mapexample.MainActivity">
</activity>
<activity
android:name="com.example.mapexample.ATMlist">
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="MY KEY HERE" />
</application>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
</manifest>
答案 0 :(得分:1)
尝试在位置访问设置中关闭GPS卫星。如果它已启用但无法访问GPS,则我的位置按钮会无声地失败;通过关闭它显然迫使该功能使用网络提供商。