gpt4 book ai didi

安卓 map 错误: Couldn't get connection factory client (with a correct ApiKey)

转载 作者:太空宇宙 更新时间:2023-11-03 11:25:47 24 4
gpt4 key购买 nike

嗨,MapActivity 启动了,它显示了一张带有纬度和经度 (0,0) 的 map ,我无法获取当前位置,因为我收到此错误:

09-16 12:06:46.515: 错误/MapActivity(464): 无法获取连接工厂客户端

apikey 是正确的,我也重新安装了 eclipse + android sdk 并重新生成了另一个 debug.keystore 及其相关的 apikey,但没有任何改变..

来源是这样的(注意我在 logcat System.out.println("* i'm here"+current_lat)) 上看不到 println);

:

package it.me.map;


import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.os.Bundle;
import android.widget.TextView;
import it.man.app.R;

public class Maps extends MapActivity
{
private TextView tvName;
private TextView tvAddress;
private TextView tvOpenTime;

private MapController mc;
private MapView mapView;

private static double current_lat;
private static double current_long;

private static LocationListener mNetworkListener = new LocationListener()
{
@Override
public void onLocationChanged(Location location) {
makeUseOfNewLocation(location);
}

@Override
public void onProviderDisabled(String provider) {}

@Override
public void onProviderEnabled(String provider) {

}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {}

public void makeUseOfNewLocation(Location location) {
current_lat = location.getLatitude();
current_long = location.getLongitude();
System.out.println("*** i'm here"+current_lat);
}
};


@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.maps);
mapView = (MapView) findViewById(R.id.mapview);
mc = mapView.getController();

LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mNetworkListener);

GeoPoint p = new GeoPoint((int)current_lat*(1000000), (int)current_long*(1000000));
mc.animateTo(p);

}

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

maps.xml 是这样的:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:enabled="true"
android:apiKey="02pmISdykDhJpseMz_d3XLv5ojPsNW25Tz9dtdA"
/>
</RelativeLayout>

最后是 AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ir.marco.furesta"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />


<application android:icon="@drawable/icon" android:label="@string/app_name">
<uses-library android:name="com.google.android.maps" />
<activity android:name=".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>
<activity android:name=".Maps"></activity>


<activity android:name=".NewsList"></activity>

</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
</manifest>

最佳答案

我想你忘了在 list 中指定 api key ,只是添加了这个权限

    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

像这样添加 api key 。

    <meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="Your api key"/>

这段代码对我有用。

    public class LocTrack extends Service implements LocationListener {

LocationManager lm;
public double lat, lon;

public boolean InitGPS() {

LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
Toast.makeText(LocTrack.this, "Please Enable GPS!", Toast.LENGTH_LONG).show();
Intent gps = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(gps);
return false;
}
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 10, this);
return true;
}

public void StopGPS() {
lm.removeUpdates(this);
}

@Override
public void onLocationChanged(Location l) {

Storage.lat = l.getLatitude();
Storage.lon = l.getLongitude();


Storage.changed = true;
Toast.makeText(LocTrack.this,"location",Toast.LENGTH_SHORT).show();
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub

}

@Override
public void onProviderEnabled(String provider) {
InitGPS();
}

@Override
public void onProviderDisabled(String provider) {
StopGPS();
}

@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}


@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
InitGPS();
return START_STICKY;
}
}

我用这个 fragment 来显示 map 。

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

关于安卓 map 错误: Couldn't get connection factory client (with a correct ApiKey),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7444543/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com