最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Import Polygon Into Google My Maps - Stack Overflow

programmeradmin1浏览0评论

Background

I have a Google Map, creating with the JavaScript API.. I have a set of polygons which are overlays on the map.

These polygons started out as KML files, but have been converted to encoded polygons. Encoding Algorithm information:

Example:

oosrFrdygOh_sJpchBoog@y{lPyylHtcA_t\praM

This is a 4 point polygon in Ohio.

Question

My question is, is there a way to import these into Google My Maps? I'd like to import these so that I can edit them.

Background

I have a Google Map, creating with the JavaScript API.. I have a set of polygons which are overlays on the map.

These polygons started out as KML files, but have been converted to encoded polygons. Encoding Algorithm information: https://developers.google./maps/documentation/utilities/polylinealgorithm

Example:

oosrFrdygOh_sJpchBoog@y{lPyylHtcA_t\praM

This is a 4 point polygon in Ohio.

Question

My question is, is there a way to import these into Google My Maps? I'd like to import these so that I can edit them.

Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Sep 28, 2015 at 19:36 KeldericKelderic 6,7179 gold badges49 silver badges89 bronze badges 2
  • Do you still have the KML files? – geocodezip Commented Sep 28, 2015 at 20:52
  • Unfortunately no. I'm working with a pre-existing app and dataset. The original developer didn't save the KML files after he encoded them. – Kelderic Commented Sep 28, 2015 at 20:54
Add a ment  | 

2 Answers 2

Reset to default 4

The answer is no, an encoded polygon cannot be imported. For a shape to be imported to My Maps, it must first be converted to a KML file.

BlueCollar laid out the first step, which is to use Google's encoding API to decode the encoded shapes into Lat/Lng pairs.

var encodedPath = 'oosrFrdygOh_sJpchBoog@y{lPyylHtcA_t\praM';
var path = google.maps.geometry.encoding.decodePath(encodedPath);

For the example encoded value, which would return:

(39.91816, -85.33082),(38.013470000000005, -85.86915),(38.22091, -83.01270000000001),(39.76632, -83.02369),(39.91816, -85.33082)

Those pairs then need to be inserted into a KML file:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis/kml/2.2">
  <Placemark>
    <name>Test Shape</name>
    <Polygon>
      <extrude>1</extrude>
      <altitudeMode>relativeToGround</altitudeMode>
      <outerBoundaryIs>
        <LinearRing>
          <coordinates>
            -85.33082,39.91816
            -85.86915,38.01347
            -83.01270000000001,38.22091
            -83.02369,39.76632
            -85.33082,39.91816
          </coordinates>
        </LinearRing>
      </outerBoundaryIs>
    </Polygon>
  </Placemark>
</kml>

The KML file can then be imported.

Try calling decodePath() on the encoded string, i.e.:

let encodedPath = 'oosrFrdygOh_sJpchBoog@y{lPyylHtcA_t\praM'; let path = google.maps.geometry.encoding.decodePath(encodedPath);

发布评论

评论列表(0)

  1. 暂无评论