【发布时间】:2015-11-16 07:57:36
【问题描述】:
我尝试了很多但仍然没有解释/解决方案,为什么地图没有加载
我正在使用
Android Studio 、Google Map V 2、Google play services 7.5.0 并完成了其他事情,例如使用 SHA1 创建 api 密钥等
我有一个名为 TestMapAct.class 的活动,其中包含在应用程序中显示地图所需的代码。
如果我将 TestMapAct 作为我的启动器活动,则地图可以工作 当我在我的启动活动之后调用它时,地图可以工作。 如果我这样调用启动活动 -> 登录活动 -> TestMapAct
,地图将不起作用这是我的 TestMapAct 类
package com.propstack.propstack.activities;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
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;
import com.propstack.propstack.R;
/**
* Created by propstack on 06-11-2015.
*/
public class TestMapAct extends FragmentActivity {
private static GoogleMap mMap;
private static Double latitude, longitude;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_location_info);
latitude = 26.78;
longitude = 72.56;
setUpMapIfNeeded();
}
public void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.location_map)).getMap();
// mMap = ((SupportMapFragment) ProfileActivity.fragmentManager
// .findFragmentById(R.id.location_map)).getMap();
// Check if we were successful in obtaining the map.
if (mMap != null)
setUpMap();
}
}
private static void setUpMap() {
// For showing a move to my loction button
mMap.setMyLocationEnabled(true);
// For dropping a marker at a point on the Map
mMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title("My Home").snippet("Home Address"));
// For zooming automatically to the Dropped PIN Location
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude,
longitude), 12.0f));
}
}
对应的XML代码:-
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/location_map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
清单详情
<permission
android:name="com.propstack.propstack.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.propstack.propstack.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<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_WIFI_STATE" />
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="Key goes here" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
地图不出现时记录猫:
ResourcesManager﹕ Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contains no resources.
ResourcesManager﹕ Asset path '/system/framework/com.android.location.provider.jar' does not exist or contains no resources.
ContextImpl﹕ Failed to ensure directory: /storage/sdcard1/Android/data/com.propstack.propstack/cache
请帮帮我
【问题讨论】:
-
你能告诉我清单中的活动吗?你在 manifest.xml 中声明了吗
-
是的,我当然已经在清单中声明了该活动
-
我建议 3 件事:将 Play Services 更新到最新的 8.3.0,使用最新的支持 Activity 类
AppCompatActivity并使用implements OnMapReadyCallback在地图准备好使用时获取回调。
标签: android dictionary