[英]error with google map v2
i am trying to display or see google maps on my app. 我正在尝试在我的应用程序上显示或查看Google地图。
i am not getting any error. 我没有任何错误。 i think problem is in xml file.fragment is not working.
我认为问题出在xml file.fragment无法正常工作。 what should i do now.
我现在应该怎么办。 plz help me with this or give me simple sample project using google map.
请帮我解决这个问题,或者使用Google Map给我简单的示例项目。 i am beginner at google map in android and trying badly to fix it but......:(
我是android中的google map的初学者,并试图进行修复,但是...... :(
here is the activity_main.xml file : 这是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"
tools:context=".MainActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>
MainActivity.java file : MainActivity.java文件:
package com.vogella.android.locationapi.maps;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
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 MainActivity extends Activity {
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_main);
/*map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
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)));
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
*/ }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
and AndroidManifest.xml file: 和AndroidManifest.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vogella.android.locationapi.maps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<permission
android:name="com.vogella.android.locationapi.maps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.vogella.android.locationapi.maps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<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" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.vogella.android.locationapi.maps.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.AIzaSyADyrVyRG68lvuQ0721D_Iaw0VLaeMjNuA"
android:value="AIzaSyADyrVyRG68lvuQ0721D_Iaw0VLaeMjNuA" />
</application>
</manifest>
Replace your meta-data
in AndroidManifest.xml
file with this one. 将此内容替换为
AndroidManifest.xml
文件中的meta-data
。
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyADyrVyRG68lvuQ0721D_Iaw0VLaeMjNuA" />
also add this meta-data
too. 也添加此
meta-data
。
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
Hope this will solve your problems. 希望这能解决您的问题。
Most importantly you have to run the application in a real device not in emulator . 最重要的是,您必须在真实设备中而不是在仿真器中运行应用程序 。 Emulator does not have
google play service
installed if you don't have any real device try to run your application in Genymotion's emulator
after installing google play service
. 模拟器没有
google play service
安装,如果你没有任何真正的设备尝试运行你的应用程序Genymotion's emulator
安装后google play service
。
You can check Running Google Maps v2 on the Android emulator. 您可以在Android模拟器上选中“ 运行Google Maps v2”。
you need to change 你需要改变
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyADyrVyRG68lvuQ0721D_Iaw0VLaeMjNuA" />
add this inside application tag
将此添加到
application tag
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
I'm posting my map fragment as a reference. 我正在发布地图片段作为参考。 You can add the missing attributes and see if it's working.
您可以添加缺少的属性,并查看其是否有效。
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
map:cameraZoom="11" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.