MapsActivity根本没有加载地图

MapsActivity根本没有加载地图

问题描述:

我已经使用默认代码来显示地图,但我不知道为什么它不起作用。我已按照“入门指南”中显示的步骤进行操作Google Maps API。我为应用程序生成了一个API密钥,并且也限制了它。MapsActivity根本没有加载地图

这是我代码MapsActivity.java

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { 

private GoogleMap mMap; 

double LATITUDE, LONGITUDE; 
String MARKER; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_maps); 

    Bundle lalo = getIntent().getExtras(); 
    if (lalo != null){ 
     LATITUDE = Double.valueOf(lalo.getString("LAT")); 
     LONGITUDE = Double.valueOf(lalo.getString("LON")); 
     MARKER = lalo.getString("MARKER"); 
    } 

    // Obtain the SupportMapFragment and get notified when the map is ready to be used. 
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
      .findFragmentById(R.id.map); 
    mapFragment.getMapAsync(this); 
} 


/** 
* Manipulates the map once available. 
* This callback is triggered when the map is ready to be used. 
* This is where we can add markers or lines, add listeners or move the camera. In this case, 
* we just add a marker near Sydney, Australia. 
* If Google Play services is not installed on the device, the user will be prompted to install 
* it inside the SupportMapFragment. This method will only be triggered once the user has 
* installed Google Play services and returned to the app. 
*/ 
@Override 
public void onMapReady(GoogleMap googleMap) { 
    mMap = googleMap; 

    LatLng location = new LatLng(LATITUDE, LONGITUDE); 
    mMap.addMarker(new MarkerOptions().position(location).title(MARKER)); 
    mMap.moveCamera(CameraUpdateFactory.newLatLng(location)); 
} 
} 

这里是MapActivity的屏幕截图。

Here

请帮我在这。

+0

你的logcat返回什么? –

+0

仔细检查API密钥的步骤,如果出现问题,您会看到类似这样的空白屏幕。另外,日志中是否有任何相关内容? –

+0

没有声明清单中 元数据 –

您是否正在使用用于调试版本的释放密钥,该名称包含“.debug”?这也会触发这种情况。您可以显示日志以获取更多详细信息。

试试这个。它适用于我

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState);  

     SupportMapFragment mapFragment = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map); 
     mapFragment.onCreate(savedInstanceState); 
     mapFragment.onResume(); 
     mapFragment.getMapAsync(this); 

    } 

    @Override 
    public void onResume() { 
     mapFragment.onResume(); 
     super.onResume(); 
    } 

    @Override 
    public void onPause() { 
     mapFragment.onPause(); 
     super.onPause(); 
    } 

    @Override 
    public void onDestroy() { 
     mapFragment.onDestroy(); 
     super.onDestroy(); 
    } 

    @Override 
    public void onLowMemory() { 
     mapFragment.onLowMemory(); 
     super.onLowMemory(); 
    } 

我解决了IntelliJ Amiya告诉寻找logcat的问题。 logcat说,授权失败,然后我解决了谷歌地图API控制台。在那里我看到我的API是正确的,但SHA1键不正确,所以我从终端生成一个并保存。我没有找到任何启​​用Google Maps Android API v2的选项。但我并未要求启用Google Maps Android API v2。否则,我只是放置了正确和新生成的SHA1密钥,并得到纠正。

感谢大家的宝贵意见。