开发者

KML -> GPolygon -> MKPolyline?

So I've got a couple of (ginormous) KML's that I've successfully converted into 180 some-odd Google-Maps encoded polygons/polylines. A开发者_如何学运维nyone have any experience or thoughts on how to take these and turn it into an MKPolyline object suitable for use on iOS4's MapKit?

Here's what I'm looking at right now .....

var sw = new GLatLng(25.8373770496571, -106.645646000733);
var ne = new GLatLng(36.50070452533, -93.50813136878951);
var bounds = new GLatLngBounds(sw, ne);
var mapZoomLevel = map.getBoundsZoomLevel(bounds);
var mapCenter = new GLatLng(31.16904078749355, -100.07688868476126)
map.setCenter(mapCenter, mapZoomLevel);

var polygon1 = new GPolygon.fromEncoded({
  polylines: [
    {points: "sxw}En~}dR@loC?puCAtt@[.......]@T^DE?z_@G^Jjw@G?",
     levels: "PBADDCCCDDACDDDDDDDBCB[.......]@EGFDEFDEDCCCDEDP",
     color: "#0000ff",
     opacity: 0.7,
     weight: 3,
     numLevels: 18,
     zoomFactor: 2}],
  fill: true,
  color: "#0000ff",
  opacity: 0.4,
  outline: true
});
map.addOverlay(polygon1);


The answer is to not do this type of conversion from KML to encoded GPolygon to MKPolyline. There's absolutely no need for the GPolygon step. As long as you've got a KML and not the compressed KMZ, you can just parse the XML to get your coordinates string to populate the MKPolyline.

If you really want to go from encoded GPolygon to MKPolyline, you've got to decode the GPolygon. It looks like Stefano Buliani figured out how to do this.

Some of the most applicable examples I found useful were the Reluctant Blogger and The Navarra Group and Mostly Harmless and (for parsing), SeismicXML.

All this got started with an attempt to take a shapefile and get it running in MapKit. While it's not exactly a straightforward solution, I've got a working (Mac-only) process now. (Hint: shapefile to kml got you down? Use ogr2ogr, part of the GDAL framework).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜