Карты Google - как получить координаты многоугольника здания по адресу?

man errno говорит:

errno определяется стандартом ISO C, чтобы быть модифицируемым lvalue интервала типа и не должен быть явно объявлен; errno может быть макросом. errno локален для потока; установка его в одном потоке не влияет на свое значение ни в каком другом потоке.

18
задан Konstantin Chernov 27 May 2015 в 19:39
поделиться

1 ответ

Могу ли я скромно предложить вам вместо этого использовать OpenStreetMaps?
Это намного проще, потому что тогда вы можете использовать OverPass API .
Однако полигоны могут не совпадать с Google-картами или опросом штата.
Последнее также верно, если вы используете Google-карты.

// https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL
private static string GetOqlBuildingQuery(int distance, decimal latitude, decimal longitude)
{
    System.Globalization.NumberFormatInfo nfi = new System.Globalization.NumberFormatInfo()
    {
        NumberGroupSeparator = "",
        NumberDecimalSeparator = ".",
        CurrencyGroupSeparator = "",
        CurrencyDecimalSeparator = ".",
        CurrencySymbol = ""
    };

    // [out: json];
    // way(around:25, 47.360867, 8.534703)["building"];
    // out ids geom meta;

    string oqlQuery = @"[out:json];
way(around:" + distance.ToString(nfi) + ", "
+ latitude.ToString(nfi) + ", " + longitude.ToString(nfi)
+ @")[""building""];
out ids geom;"; // ohne meta - ist minimal

    return oqlQuery;
}




public static System.Collections.Generic.List<Wgs84Point> GetWgs84PolygonPoints(int distance, decimal latitude, decimal longitude)
{
    string[] overpass_services = new string[] {
        "http://overpass.osm.ch/api/interpreter",
        "http://overpass.openstreetmap.fr/api/interpreter",
        "http://overpass-api.de/api/interpreter",
        "http://overpass.osm.rambler.ru/cgi/interpreter",
        // "https://overpass.osm.vi-di.fr/api/interpreter", // offline...
    };

    // string url = "http://overpass.osm.ch/api/interpreter";
    // string url = "http://overpass-api.de/api/interpreter";
    string url = overpass_services[s_rnd.Next(0, overpass_services.Length)];


    System.Collections.Specialized.NameValueCollection reqparm = new System.Collections.Specialized.NameValueCollection();
    reqparm.Add("data", GetOqlBuildingQuery(distance, latitude, longitude));

    string resp = PostRequest(url, reqparm);
    // System.IO.File.WriteAllText(@"D:\username\Documents\visual studio 2017\Projects\TestPlotly\TestSpatial\testResponse.json", resp, System.Text.Encoding.UTF8);
    // System.Console.WriteLine(resp);
    // string resp = System.IO.File.ReadAllText(@"D:\username\Documents\visual studio 2017\Projects\TestPlotly\TestSpatial\testResponse.json", System.Text.Encoding.UTF8);

    System.Collections.Generic.List<Wgs84Point> ls = null;

    Overpass.Building.BuildingInfo ro = Overpass.Building.BuildingInfo.FromJson(resp);

    if (ro != null && ro.Elements != null && ro.Elements.Count > 0 && ro.Elements[0].Geometry != null)
    {
        ls = new System.Collections.Generic.List<Wgs84Point>();

        for (int i = 0; i < ro.Elements[0].Geometry.Count; ++i)
        {
            ls.Add(new Wgs84Point(ro.Elements[0].Geometry[i].Latitude, ro.Elements[0].Geometry[i].Longitude, i));
        } // Next i 

    } // End if (ro != null && ro.Elements != null && ro.Elements.Count > 0 && ro.Elements[0].Geometry != null) 


    return ls;
} // End Function GetWgs84Points 
2
ответ дан 30 November 2019 в 08:09
поделиться
Другие вопросы по тегам:

Похожие вопросы: