这篇文章主要围绕android-如何向GoogleMapApiv2添加基本网格和googlemap怎么用展开,旨在为您提供一份详细的参考资料。我们将全面介绍android-如何向GoogleMapAp
这篇文章主要围绕android-如何向GoogleMap Api v2添加基本网格和googlemap怎么用展开,旨在为您提供一份详细的参考资料。我们将全面介绍android-如何向GoogleMap Api v2添加基本网格的优缺点,解答googlemap怎么用的相关问题,同时也会为您带来Android 2.3和Google Maps API v2、Android Google Map API V2 (key 申请)、Android Google Map API V2(显示地图)、Android Google Maps Api V2,获取当前地图中心的坐标的实用方法。
本文目录一览:- android-如何向GoogleMap Api v2添加基本网格(googlemap怎么用)
- Android 2.3和Google Maps API v2
- Android Google Map API V2 (key 申请)
- Android Google Map API V2(显示地图)
- Android Google Maps Api V2,获取当前地图中心的坐标
android-如何向GoogleMap Api v2添加基本网格(googlemap怎么用)
我想将以前用于地图的基本网格添加到我的GoogleMap中.
我阅读了文档,但没有找到任何有帮助的方法,也许TileOverlay或GroundOverlay可以解决问题,但是我没有找到任何示例或教程,甚至在官方示例中也没有.
有人可以建议我一些可行的方法吗?
E D I T:
是的,我想要这样的网格线:
解决方法:
好像我有一个代码可以做到这一点.我仅将其用于调试,但这里是:DebugHelper.java.
一些注意事项:
>您还必须复制SphericalMercator.java
>将IGoogleMap更改为原始GoogleMap,将IProjection更改为Projection
> clusterSize参数以度为单位,因此您必须根据缩放比例进行更改
>最后:在onCameraChange中调用drawDebugGrid.
如果要查看它的实际效果,可以运行Android Maps Extensions演示.要查看网格,唯一需要做的更改是在GridClusteringStrategy.java的第一行中将DEBUG_GRID设置为true.
Android 2.3和Google Maps API v2
今天,我尝试使用适用于Android 2.3.3的Google Maps api v2我的步骤:
- 从debug.keystore获得SHA1代码
- 在Google API控制台中创建一个新项目
- 注册一个新的ID
- 启用了Google Maps android api v2
- 使用输入SHA1创建一个Android密钥; it.mappe(it.mappe是我的包)
- 获取API密钥
- 更新AndroidManifest文件:
<permission android:name="it.mappe.permission.MAPS_RECEIVE" android:protectionLevel="signature" /> <uses-permission android:name="it.mappe.permission.MAPS_RECEIVE" /> <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="16" /> <uses-permission android:name="android.permission.INTERNET" /> <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" /> <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> <uses-feature android:glEsVersion="0x00020000" android:required="true"` /> <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="MY_KEY" /> <activity android:name="it.mappe.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> </application>
- 我的主要活动
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); }
我的activity_main:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/map"android:layout_width="match_parent"android:layout_height="match_parent"/>
将目录复制
ANDROID_SDK_DIR/extras/google/google_play_services/libproject/google-play-services_lib
到项目的根目录添加
/extras/android/compatibility/v4/android-support-v4.jar
为外部罐将下一行添加到
YOUR_PROJECT/project.properties
android.library.reference.1=google-play-services_lib
当我在三星银河S上运行它(使用Google Play服务apk)时,它崩溃并且logcat显示此错误
E/AndroidRuntime(6435): FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{it.mappe/it.mappe.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667) at android.app.ActivityThread.access$1500(ActivityThread.java:117) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:123) at android.app.ActivityThread.main(ActivityThread.java:3687) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) at dalvik.system.NativeStart.main(Native Method) Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581) at android.view.LayoutInflater.inflate(LayoutInflater.java:386) at android.view.LayoutInflater.inflate(LayoutInflater.java:320) at android.view.LayoutInflater.inflate(LayoutInflater.java:276) at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:209) at android.app.Activity.setContentView(Activity.java:1657) at it.mappe.MainActivity.onCreate(MainActivity.java:12) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615) ... 11 more Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/it.mappe-2.apk] at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240) at java.lang.ClassLoader.loadClass(ClassLoader.java:551) at java.lang.ClassLoader.loadClass(ClassLoader.java:511) at android.view.LayoutInflater.createView(LayoutInflater.java:471) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549) at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568) ... 19 more
一些建议?
编辑
这是我的main.xml:
<fragment xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent"/>
答案1
小编典典<fragment>
应该全部小写。
另外,您正在使用Activity
(不是FragmentActivity
)与SupportMapFragment
,并且我怀疑该组合是否有效。
Android Google Map API V2 (key 申请)
要使用V2 的API,需要到Google APIs Console将Google Maps Android API v2服务开启(前提是你已经拥有Google帐号,并创建一个项目),见图:
然后用keystore 的SHA1 加package申请API key,
填入SHA1和包名(用包名前缀,这样可以给多个应用使用)
申请成功的KEY
至此API key 申请完成,接下来就可以进行Google Map 的开发了。
Android Google Map API V2(显示地图)
检查Android SDK ,确保Google Play service已经安装,现象见图:
开发的应用要支持2.2+导入Froyo的工程,支持3.1+的,使用第二个。Google Map Lib 的工程位于 ~/android Sdk/extras/google/,选择合适的工程导入eclipse。
创建自己的工程,然后将上面的工程作为库,引进来
AndroidManifest.xml的配置
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sample.app"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<!-- permission -->
<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"/>
<!-- OpenGL ES 2 -->
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name="com.sample.app.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>
<!-- Google Map V2 key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="API_KEY"/>
</application>
</manifest>
布局文件:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
Activity
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
执行结果:
Android Google Maps Api V2,获取当前地图中心的坐标
我在考虑使用
@Override public void onCameraChange(CameraPosition arg0) { // Todo Auto-generated method stub geoCodeCenter(/*Location object*/); }
但我无法从CameraPosition对象获取lat / long.相机也有更多的尺寸,因为你现在也可以看到不同间距的地图,所以获得纬度/经度的中心是不一样的,因为用户不能保证从鸟瞰图看地图,除非某些手势被禁用.
有一个更好的方法吗?我不希望用户长时间点击标记将其拖动到地图上,我希望他们只需知道用户平移地图中心的位置.
map.getMyLocation()方法用于其他内容,例如当前的LocationProvider位置.尽管我使用GPS并且它仍然返回null,但也看似不是选项
解决方法
but I can’t get the lat/long from the CameraPosition object
根据我对文档的阅读,CameraPosition上的target
public data member是地图中心的LatLng.
今天的关于android-如何向GoogleMap Api v2添加基本网格和googlemap怎么用的分享已经结束,谢谢您的关注,如果想了解更多关于Android 2.3和Google Maps API v2、Android Google Map API V2 (key 申请)、Android Google Map API V2(显示地图)、Android Google Maps Api V2,获取当前地图中心的坐标的相关知识,请在本站进行查询。
本文标签: