谷歌地图不工作的两个仿真器和设备 [英] google map not working on both emulator and device

查看:121
本文介绍了谷歌地图不工作的两个仿真器和设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行一个简单的谷歌地图,但它不工作了 仅显示地图background.checked在两个模拟器和设备。

  

XML文件: -

 <片段的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:ID =@ + ID /图
  机器人:layout_width =match_parent
  机器人:layout_height =match_parent
  类=com.google.android.gms.maps.SupportMapFragment/>
 

  

进口android.os.Bundle;进口   com.google.android.gms.maps.GoogleMap;进口   com.google.android.gms.maps.SupportMapFragment;进口   com.google.android.gms.maps.model.BitmapDesc​​riptorFactory;进口   com.google.android.gms.maps.model.LatLng;进口   com.google.android.gms.maps.model.Marker;进口   com.google.android.gms.maps.model.MarkerOptions;

     

公共类LocationGB扩展   android.support.v4.app.FragmentActivity {static final的经纬度   汉堡=新的经纬度(53.558,9.927); static final的经纬度基尔=新   经纬度(53.551,9.993);私人GoogleMap的地图;           @覆盖保护无效的onCreate(包savedInstanceState){         super.onCreate(savedInstanceState);         的setContentView(R.layout.activity_location);         地图=((SupportMapFragment)getSupportFragmentManager()findFragmentById(android.R.id.content)。)的GetMap();

 如果(图!= NULL){
    标记汉堡= map.addMarker(新MarkerOptions()。位置(汉堡)
        .title伪(汉堡));
    标记基尔= map.addMarker(新MarkerOptions()
        .position(基尔)
        .title伪(基尔)
        是.snippet(基尔是酷)
        .icon(BitmapDesc​​riptorFactory
            .fromResource(R.drawable.ic_launcher)));
  }
        }}
 

解决方案

在你的manifest文件中必须添加:

 <许可
  机器人:名称=your.application.package.permission.MAPS_RECEIVE
  安卓的ProtectionLevel =签名/>
 

像是: your.application.package 即可: com.themontcalm.droid

是的,如果你使用的是

 <使用库机器人:名称=com.google.android.maps/>
 

然后从清单文件中删除:

和增加你的API code在清单文件也:

 <元数据
        机器人:名称=com.google.android.maps.v2.API_KEY
        机器人:值=Your_Map_Key/>
 

和清单文件你缺少这样的:

 <使用特征
    机器人:glEsVersion =0x00020000
    机器人:要求=真/>
 

这样也增加了,这也清单文件:

您应该修改 android.R.id.content R.id.map 在code

是这样的:

 地图=((SupportMapFragment)getSupportFragmentManager()findFragmentById(R.id.map)。)的GetMap()。
 

I am trying to run a simple google map but its not working its showing only map background.checked on both emulator and device.

xml file:-

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/map"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  class="com.google.android.gms.maps.SupportMapFragment"/>

import android.os.Bundle; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Marker; import com.google.android.gms.maps.model.MarkerOptions;

public class LocationGB extends android.support.v4.app.FragmentActivity { static final LatLng HAMBURG = new LatLng(53.558, 9.927); static final LatLng KIEL = new LatLng(53.551, 9.993); private GoogleMap map; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_location); map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(android.R.id.content)).getMap();

  if (map!=null){
    Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
        .title("Hamburg"));
    Marker kiel = map.addMarker(new MarkerOptions()
        .position(KIEL)
        .title("Kiel")
        .snippet("Kiel is cool")
        .icon(BitmapDescriptorFactory
            .fromResource(R.drawable.ic_launcher))); 
  }
        } }

解决方案

In your manifest file you have to add:

<permission
  android:name="your.application.package.permission.MAPS_RECEIVE"
  android:protectionLevel="signature" />

Like from: your.application.package to: com.themontcalm.droid

And yes if you are using

<uses-library android:name="com.google.android.maps" />

then remove from manifest file:

and add your api code to in manifest file also:

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

And in manifest file you are missing this:

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

so also add to this also in manifest file:

you should change android.R.id.content with R.id.map in your code

Something like:

map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

这篇关于谷歌地图不工作的两个仿真器和设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆