我在我的应用程序中设置谷歌地图,它顺利且没有错误,但地图只是没有加载任何内容。 Cat日志表示它使用" Google Play服务客户端版本:4452000"之后" Google Play服务包版本:5089038" ,这是正常的吗?
这就是它的样子:
FragmentManager fmanager = getSupportFragmentManager();
Fragment fragment = fmanager.findFragmentById(R.id.map_view);
SupportMapFragment supportmapfragment = (SupportMapFragment)fragment;
GoogleMap supportMap = supportmapfragment.getMap();
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map_view"
android:layout_width="match_parent"
android:layout_height="400dp"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
I/Google Maps Android API(23503): Google Play services client version: 4452000
I/dalvikvm(23503): Could not find method gui.a, referenced from method gqh.a
W/dalvikvm(23503): VFY: unable to resolve static method 24934: Lgui;.a (Landroid/content/Context;)Lgrh;
D/dalvikvm(23503): VFY: replacing opcode 0x71 at 0x0003
E/dalvikvm(23503): Could not find class 'gpq', referenced from method gpr.a
W/dalvikvm(23503): VFY: unable to resolve new-instance 4090 (Lgpq;) in Lgpr;
D/dalvikvm(23503): VFY: replacing opcode 0x22 at 0x0000
E/dalvikvm(23503): Could not find class 'gpq', referenced from method gpr.a
W/dalvikvm(23503): VFY: unable to resolve new-instance 4090 (Lgpq;) in Lgpr;
D/dalvikvm(23503): VFY: replacing opcode 0x22 at 0x0000
E/dalvikvm(23503): Could not find class 'gpq', referenced from method gpr.a
W/dalvikvm(23503): VFY: unable to resolve new-instance 4090 (Lgpq;) in Lgpr;
D/dalvikvm(23503): VFY: replacing opcode 0x22 at 0x0000
D/dalvikvm(23503): DexOpt: unable to opt direct call 0x5ea1 at 0x0a in Lgpr;.a
D/dalvikvm(23503): DexOpt: unable to opt direct call 0x5ea1 at 0x0c in Lgpr;.a
D/dalvikvm(23503): DexOpt: unable to opt direct call 0x5ea1 at 0x0a in Lgpr;.a
D/dalvikvm(23503): GC_FOR_ALLOC freed 433K, 9% free 19472K/21336K, paused 13ms, total 13ms
I/Google Maps Android API(23503): Google Play services package version: 5089038
W/dalvikvm(23503): VFY: unable to resolve static field 20875 (t) in Lyo;
D/dalvikvm(23503): VFY: replacing opcode 0x62 at 0x000e
W/dalvikvm(23503): VFY: unable to resolve static field 20875 (t) in Lyo;
D/dalvikvm(23503): VFY: replacing opcode 0x62 at 0x000d
D/dalvikvm(23503): GC_FOR_ALLOC freed 585K, 8% free 19817K/21336K, paused 13ms, total 13ms
I/dalvikvm(23503): Failed resolving Lcom/google/android/gms/location/internal/ParcelableGeofence; interface 4023 'Lglm;'
W/dalvikvm(23503): Link of class 'Lcom/google/android/gms/location/internal/ParcelableGeofence;' failed
E/dalvikvm(23503): Could not find class 'com.google.android.gms.location.internal.ParcelableGeofence', referenced from method gls.a
W/dalvikvm(23503): VFY: unable to resolve check-cast 2086 (Lcom/google/android/gms/location/internal/ParcelableGeofence;) in Lgls;
D/dalvikvm(23503): VFY: replacing opcode 0x1f at 0x0019
D/dalvikvm(23503): GC_FOR_ALLOC freed 155K, 4% free 20608K/21336K, paused 13ms, total 14ms
V/QcrilMsgTunnelSocket( 1866): After reading offset = 0 remaining = 4 countRead = 4
D/QcrilMsgTunnelSocket( 1866): messageLength extracted from first 4 inputStream reads = 29
V/QcrilMsgTunnelSocket( 1866): offset = 0 remaining = 29 countRead = 0
V/QcrilMsgTunnelSocket( 1866): offset = 0 remaining = 29 countRead = 29
D/QcrilMsgTunnelSocket( 1866): readRilMessage: Buffer = [B@425f22a0 HexData = [0100000004040000110000005155414c434f4d4def0308000100000003]
V/QcrilMsgTunnelSocket( 1866): Read packet: 29 bytes. Data Available = 32 Position = 0
D/QcrilMsgTunnelSocket( 1866): processResponse. message type = 1. Data Available = 28
D/QcrilMsgTunnelSocket( 1866): ByteArray from parcel = 5155414c434f4d4def0308000100000003
D/QcrilMsgTunnelSocket( 1866): Received RIL_UNSOL_OEM_HOOK_RAW message
D/QcrilMsgTunnelSocket( 1866): Oem ID in RIL_UNSOL_OEM_HOOK_RAW is QUALCOMM
D/QcrilMsgTunnelSocket( 1866): OEM ID check Passed
D/QcrilMsgTunnelSocket( 1866): Response ID in RIL_UNSOL_OEM_HOOK_RAW is 525295
D/QcrilMsgTunnelSocket( 1866): Response ID 525295is not served in this process.
D/QcrilMsgTunnelSocket( 1866): To broadcast an Intent via the notifier to external apps
D/QcrilMsgTunnelIfaceManager( 1866): handleMessage what=0
D/QcrilMsgTunnelIfaceManager( 1866): Broadcasting intent ACTION_UNSOL_RESPONSE_OEM_HOOK_RAW
V/QcrilMsgTunnelSocket( 1866): Before reading offset = 0 remaining = 4 countRead = 0
I/Google Maps Android API(23503): Failed to contact Google servers. Another attempt will be made when connectivity is established
D/MobileDataStateTracker( 785): default: setPolicyDataEnable(enabled=true)
E/Google Maps Android API(23503): Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).
答案 0 :(得分:1)
测试时需要使用其他API密钥。它与您从密钥库文件生成的API密钥不同。
来自eclipse - &gt; windows - &gt;偏好设置 - &gt; Android - &gt; Build。使用此SHA1指纹并从Google API控制台获取另一个API密钥并将其用于测试。
在将APK上传到Google Play之前,请不要忘记将其更改为制作版。
<强>更新强> 我用这种方式,它工作正常。它与你使用的不同:
fragment_map.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.google.android.gms.maps.MapView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
这是我的MapFragment类。我在地图上找到一个点并给它一个标题:
public class MapFragment extends Fragment {
final static String TAG = "map";
final static String LONG = "long";
final static String LAT = "lat";
final static String TITLE = "title";
private MapView mMapView;
private GoogleMap mMap;
private Bundle mBundle;
Bundle args;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View inflatedView = inflater.inflate(R.layout.fragment_map, container, false);
MapsInitializer.initialize(getActivity());
mMapView = (MapView) inflatedView.findViewById(R.id.map);
mMapView.onCreate(mBundle);
setUpMapIfNeeded(inflatedView);
return inflatedView;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBundle = savedInstanceState;
args = getArguments();
}
private void setUpMapIfNeeded(View inflatedView) {
if (mMap == null) {
mMap = ((MapView) inflatedView.findViewById(R.id.map)).getMap();
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(args.getDouble(LAT), args.getDouble(LONG))).title(args.getString(TITLE)));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(args.getDouble(LAT), args.getDouble(LONG)), 15));
}
@Override
public void onResume() {
super.onResume();
mMapView.onResume();
}
@Override
public void onPause() {
super.onPause();
mMapView.onPause();
}
@Override
public void onDestroy() {
mMapView.onDestroy();
super.onDestroy();
}
@Override
public void onStart() {
super.onStart();
}
}
这就是我将它添加到屏幕的方式:
MapFragment mapFragment = new MapFragment();
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
Bundle args = new Bundle();
args.putString(MapFragment.TITLE, title);
args.putDouble(MapFragment.LONG, longitude);
args.putDouble(MapFragment.LAT, latitude);
mapFragment.setArguments(args);
transaction.replace(R.id.content_frame, mapFragment,"map");
transaction.addToBackStack(null);
transaction.commit();
我希望它有所帮助。
答案 1 :(得分:0)
尝试以下代码。这对我有用......
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:name="com.google.android.gms.maps.MapFragment"
android:id="@+id/thapar_map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
setContentView(R.layout.maps);
GoogleMap map;
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.thapar_map)).getMap();
map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
map.setPadding(5, 5, 5, 5);
map.setMyLocationEnabled(true);
答案 2 :(得分:0)
根据我的理解,这个问题正在发生,原因有三个
<强>原因强> 1)首先是缺乏互联网连接
2)第二个是你的谷歌api密钥不匹配
3)如果密钥正常,则第三个密钥生成期间提供的软件包名称与项目软件包名称不完全相同
<强>解决方案强> 首先,你需要检查你的网络连接是否正常,然后你需要更进一步
对于第二个和第三个,您需要使用适当的步骤创建密钥 如果你使用eclipse那么
Eclipse - &gt; windows - &gt;偏好设置 - &gt; Android - &gt;构建您将获得SHA密钥
使用该SHA键生成Android密钥
粘贴SHA键后,按照符号“;”附加项目包名称
例如
<强> YOR_SHA_KEY; YOUR_PROJECT_MAIN_PACKAGE_NAME 强> 然后生成密钥最后你会得到谷歌地图密钥为Android使用,希望它将解决你的问题,确保你使用相同的pakcage名称,这是你的项目包名称
希望它能解决您的问题快乐编码:)