我正在使用Google Maps API(v2)开发Android应用程序。我想显示国家边界,但不显示国家/地区名称或任何其他信息(静音地图)。 应用程序的目的是创建地理游戏。
考虑到如文档[{3}}中所述,我首先考虑将每个国家/地区边界绘制为线条(使用The Google Maps Android API does not support custom styles)。那么,我用Google搜索了一下,发现已经完成了Polylines。它采用KML格式,易于导入Google地球应用程序以及Google地图Polygon approximation of all countries,但我无法找到Android的导入方法。
KML文件中的国家/地区的格式类似以下(下载为csv),以防国家/地区只需要表示一个Polygon:
Andorra,"
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
1.78172,42.569962 1.723611,42.509438 1.445833,42.601944 1.78172,42.569962
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>"
这种格式如果它有多个Polygon:
Mayotte,"
<MultiGeometry>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
45.282494,-12.80417 45.262497,-12.76889 45.283051,-12.7475 45.282494,-12.80417
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
45.204994,-12.84972 45.097496,-12.985834 45.078888,-12.6625 45.204994,-12.84972
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</MultiGeometry>
在这一步中,我想到了一个解决方案:
// Instantiates a new Polygon object and adds points to define a rectangle
PolygonOptions rectOptions = new PolygonOptions()
.add(new LatLng(37.35, -122.0),
new LatLng(37.45, -122.0),
new LatLng(37.45, -122.2),
new LatLng(37.35, -122.2),
new LatLng(37.35, -122.0));
myMap.addPolygon(rectOptions);
我本可以使解决方案有效,但是由于我想要更多的功能,比如只画一些大陆,解决方案是不够的。
最后,我认为使用以下结构将KML文件转换为XML文件(并且具有强大的Python基础,认为XML很容易解析)会更好(也更容易理解):< / p>
<continent name="Europe">
<country name="Andorra">
//As many polygons as necessary
<poligon1>
//Coordinates go here
</poligon1>
<poligonN>
//Coordinates go here
</poligonN>
</country>
</continent>
我已经知道如何将KML转换为XML,但Android中有许多解析器,如DOM,SAX,XMLPull ......:
请注意,这种浏览XML的想法是不固定和 如果有人有其他想法,我会很高兴听到他们。