谷歌地图V2不是为我工作。任何样品? [英] Google Map V2 not working for me . Any sample?

查看:110
本文介绍了谷歌地图V2不是为我工作。任何样品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用的谷歌地图V2 的许多样品,我按照所有所必需的这个事情。但仍然有问题,只有地图视图显示和我的当前位置没有被我的模拟器显示

我已经创建了我从API控制台系统MD 5键和API密钥和使用清单中的SHA 1键。但仍然有问题。

所以,请帮助我。

我的资料来源$ C ​​$ C:

MainActivity.java

 包com.googlev2.android;进口android.os.Bundle;
进口android.app.Activity;
进口android.support.v4.app.FragmentActivity;
进口android.view.Menu;进口com.google.android.gms.maps.GoogleMap;
进口com.google.android.gms.maps.MapFragment;
进口com.google.android.gms.maps.SupportMapFragment;
进口com.google.android.gms.maps.model.LatLng;
进口com.google.android.gms.maps.model.Marker;
进口com.google.android.gms.maps.model.MarkerOptions;公共类MainActivity扩展FragmentActivity {私人GoogleMap的MMAP;@覆盖
保护无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);    SupportMapFragment FM =(SupportMapFragment)getSupportFragmentManager()。
            findFragmentById(R.id.map);
    MMAP = fm.getMap();    mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);    最后的经纬度CIU =新的经纬度(35.21843892856462,33.41662287712097);
    标记CIU = mMap.addMarker(新的MarkerOptions()位置(CIU).title伪(我的办公室));   }@覆盖
公共布尔onCreateOptionsMenu(菜单菜单)
    {
    //充气菜单;如果是present这增加了项目操作栏。
    。getMenuInflater()膨胀(R.menu.main,菜单);
    返回true;
    }  }

和activity_main.xml中

 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
的xmlns:工具=htt​​p://schemas.android.com/tool​​s
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:paddingBottom会=@扪/ activity_vertical_margin
机器人:paddingLeft =@扪/ activity_horizo​​ntal_margin
机器人:paddingRight =@扪/ activity_horizo​​ntal_margin
机器人:paddingTop =@扪/ activity_vertical_margin
工具:上下文=MainActivity。><的TextView
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字=@字符串/参考hello world/><片段
    机器人:名字=com.google.android.gms.maps.SupportMapFragment
    机器人:ID =@ + ID /图
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    />
 < / RelativeLayout的>

和AndroidManifest.xml中:

 <?XML版本=1.0编码=UTF-8&GT?;
  <清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=com.googlev2.android
    安卓版code =1
     机器人:=的versionName1.0>   <用途-SDK
    安卓的minSdkVersion =8
    机器人:targetSdkVersion =17/>  <使用许可权的android:NAME =android.permission.INTERNET对/>
  <使用许可权的android:NAME =com.google.android.providers.gsf.permission.READ_GSERVICES/>
 <使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAG​​E/>
 <使用许可权的android:NAME =android.permission.ACCESS_COARSE_LOCATION/>
 <使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/>
    <许可
    机器人:名字=com.googlev2.android.permission.MAPS_RECEIVE
    安卓的ProtectionLevel =签名>
    < /许可>    <使用许可权
    机器人:名字=com.googlev2.android.permission.MAPS_RECEIVE/>
<用途特征
    机器人:glEsVersion =0x00020000
    机器人:要求=真/>
<使用许可权的android:NAME =android.permission.ACCESS_NETWORK_STATE/><应用
    机器人:allowBackup =真
    机器人:图标=@绘制/ ic_launcher
    机器人:标签=@字符串/ APP_NAME
    机器人:主题=@风格/ AppTheme>
      <! - <元数据
        机器人:名字=com.google.android.maps.v2.API_KEY
        机器人:值=AIzaSyDciL7-T3BphxGv2q-A77vNrcyJQ_sTrgI/> - >    <活动
        机器人:名字=com.googlev2.android.MainActivity
        机器人:标签=@字符串/ APP_NAME>
        &所述;意图滤光器>
            <作用机器人:名字=android.intent.action.MAIN/>            <类机器人:名字=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>
    < /活性GT;     <! - <元数据
        机器人:名字=com.google.android.maps.v2.API_KEY
        机器人:值=AIzaSyBDUb-4cOST​​eeH3XqVQHwzXL2bT0aAM2h8/>         - >         &所述;元数据
        机器人:名字=com.google.android.maps.v2.API_KEY
        机器人:值=AIzaSyDiLovJFMLKEZkI5Ijtl0fKA-qApScD_Pk/>
  < /用途>< /清单>


解决方案

如果您的清单文件是正确试试这个男人

activity_main.xml中

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直><片段
    机器人:名字=com.google.android.gms.maps.SupportMapFragment
    的xmlns:地图=htt​​p://schemas.android.com/apk/res-auto
    机器人:ID =@ + ID /图
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    图:cameraTargetLat =33.41662287712097
    图:cameraTargetLng =35.21843892856462
    图:cameraZoom =4/>< / LinearLayout中>

在MainActivity.java的onCreate()

 公共类MainActivity扩展FragmentActivity {私人GoogleMap的MMAP;@覆盖
保护无效的onCreate(捆绑savedInstanceState){    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);    SupportMapFragment mapFragment =(SupportMapFragment)getSupportFragmentManager()findFragmentById(R.id.map)。
    GoogleMap的MMAP = mapFragment.getMap();    mMap.addMarker(新的MarkerOptions()
    .POSITION(新经纬度(35.21843892856462,33.41662287712097))
    .title伪(我的办公室));}

下面是我的手机上的结果

I have used many samples of Google map V2, and i have followed all the things which are necessary for this. But still having problem, only map view is showing and my current location is not being displayed on my emulator.

I have already created my system MD 5 key and API key from API console and used the SHA 1 key in manifest. But still having problem.

So please help me.

My Source Code :

MainActivity.java

package com.googlev2.android;

import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.SupportMapFragment;
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 MainActivity extends FragmentActivity {

private GoogleMap mMap;

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

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

    mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);

    final LatLng CIU = new LatLng(35.21843892856462, 33.41662287712097);
    Marker ciu = mMap.addMarker(new MarkerOptions().position(CIU).title("My Office"));

   }

@Override
public boolean onCreateOptionsMenu(Menu menu)
    {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
    }

  }

And activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

<fragment
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />


 </RelativeLayout>

And AndroidManifest.xml :

  <?xml version="1.0" encoding="utf-8"?>
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.googlev2.android"
    android:versionCode="1"
     android:versionName="1.0" >

   <uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

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


    <permission 
    android:name="com.googlev2.android.permission.MAPS_RECEIVE" 
    android:protectionLevel="signature">
    </permission>

    <uses-permission 
    android:name="com.googlev2.android.permission.MAPS_RECEIVE"/>


<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
      <!-- <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyDciL7-T3BphxGv2q-A77vNrcyJQ_sTrgI"/> -->

    <activity
        android:name="com.googlev2.android.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>

     <!--   <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyBDUb-4cOSTeeH3XqVQHwzXL2bT0aAM2h8"/>

        -->

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


  </application>

</manifest>

解决方案

If your manifest file is correct Try this man

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<fragment
    android:name="com.google.android.gms.maps.SupportMapFragment"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    map:cameraTargetLat="33.41662287712097"
    map:cameraTargetLng="35.21843892856462"
    map:cameraZoom="4"/>

</LinearLayout>

In MainActivity.java onCreate()

public class MainActivity extends FragmentActivity  {

private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

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

    mMap.addMarker(new MarkerOptions()
    .position(new LatLng(35.21843892856462, 33.41662287712097))
    .title("My Office"));

}

Here is the result on my phone

这篇关于谷歌地图V2不是为我工作。任何样品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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