Android应用程式中Google Maps上的KML [英] KML on Google Maps in android application

查看:92
本文介绍了Android应用程式中Google Maps上的KML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能知道如何在android应用中将KML图层添加为Google地图的叠加层.

Can anyone know how to add the KML layer on the android app as an overlay in the google map.

KML不是静态的KML文件,只能由用户上传.而且我必须将KML上传到我的服务器,然后我要在android应用程序本身中显示的Google地图中显示相应的KML图层.

The KML is not a static KML file that may uploaded by the user only. And i have to upload the KML to my server then i want to show the corresponding KML layer in the google map which is displaying in the android application itself.

有什么主意吗?请举一些例子.

Have any idea ?. Please suggest some examples.

我是KML的新手.所以请...

I'm new in the KML. So please...

推荐答案

要执行相同的操作...

To do the same...

1)在资源文件夹下创建一个文件夹(名为"raw"(执行您想提供的操作.请不要忘记在访问KLM文件时更改名称)) 例如:-res/raw

1) Make one folder under your resource folder( named as "raw" (Do whate ever you want to give. Please dont forget to change the name while accessing the KLM file )) eg:- res/raw

2)将 KML 放在此文件夹中.

2) Place your KML in this folder.

3)在您的活动中,

为图层创建变量

 KmlLayer layer;

4)在您的 onCreate 函数中,只需调用KML文件.即创建图层.

4) In your onCreate function just call the KML file. Ie create the layer.

layer = new KmlLayer(googleMap, R.raw.landmarkkml, getApplicationContext());

这里有三个参数.

第一个Google地图对象. 第二个KML文件路径. 第三个应用程序上下文.

1st one google map object. 2nd one KML file path . 3rd the application context.

5)现在,我们必须在kmllayer中添加Google地图.

5) Now we have to add the kmllayer with the google map.To do that,

 layer.addLayerToMap();

完整代码

package com.yourdomain.kmlongooglemap;
import android.app.Activity;
import android.content.Context;
public class KmlActivity extends Activity {
private GoogleMap googleMap; // Google map object.
KmlLayer layer; //KML object.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.kmlactivitylayout); 
    try {
        layer = new KmlLayer(googleMap,R.raw.lanmark, getApplicationContext()); // creating the kml layer
        layer.addLayerToMap();// adding kml layer with the **google map**
    } catch (Exception e) {
        e.printStackTrace();
    }
  });

}

您可以运行您的应用程序.在此处,您可以在 GOOGLE MAP 上看到 KML .

the you can run your application.Here you can see the KML on your GOOGLE MAP.

谢谢.

这篇关于Android应用程式中Google Maps上的KML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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