【问题标题】:Point to latlng conversion from Google Earth KML file从 Google 地球 KML 文件指向经纬度转换
【发布时间】:2012-10-20 19:58:17
【问题描述】:

我在提取 Google 地球坐标时遇到问题,因为我需要它在 latlng 而不是 GPoint 中,并且需要暴露给我的 Google Map 应用程序,我知道我可以使用这些点在 gmap 中显示我的数据,但仍然需要转换为 latlng,我的 nodejs 脚本是它的

var fs = require('fs'),
    xml2js = require('xml2js');

var parser = new xml2js.Parser();
fs.readFile(__dirname + '/doc.xml', function(err, data) {
    parser.parseString(data, function (err, result) {
        var data = [];
        for (var i in result.data.Placemark) {
            var row = result.data.Placemark[i];
            var point = row.Point[0].coordinates.toString().split(',');
            row = {
                name            : row.name[0]
                , description   : row.description[0]
                , geolocation   : [point[0], point[1]]
            };
            data.push(row);
        }

        console.log(data);
    });
});

此时我能够提取所有我想要的数据(我刚刚从 KML 中删除了所有不必要的标签)。但我需要将其规范化为 latlng,因为我的其他数据库文档 (noSQL) 都在 latlng 中。

【问题讨论】:

    标签: javascript node.js google-maps google-maps-api-3 google-earth


    【解决方案1】:

    颠倒point[0](经度)、point[1](纬度)的顺序。

    变化:

        geolocation   : [point[0], point[1]]
    

    收件人:

        geolocation   : [point[1], point[0]]
    

    【讨论】:

    • Google 没有指定KML,它是由 Keyhole, Inc 创建的,该公司于 2004 年被 Google 收购。
    猜你喜欢
    • 2012-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-11
    • 1970-01-01
    相关资源
    最近更新 更多