Parsing KML Coordinates as LatLng

914 views
Skip to first unread message

Matthew W. Shepherd

unread,
Aug 2, 2011, 11:49:19 AM8/2/11
to Google Maps JavaScript API v3
I'll preface this by noting that I am still early in the stages of
learning Javascript, but I have so far been relatively successful with
the Google Maps API. I'm also leaving out extensive code because I
feel that this is simple enough to preclude lengthy examples.

I'm using the Maps API in tandem with Fusion Tables to map various
placemarks. The data came from an imported KML file, so the
coordinates of each placemark are rendered in the table as Geometry
strings in the form "<Point><coordinates>longitude, latitude,
altitude</coordinates></Point>". The Google Maps Visualization layer
renders properly with all of the placemarks.

The problem I'm running into is that I would like to use these
coordinates to define the position of an info window corresponding to
a selected data row. I can't figure out an elegant way to define lat
and lng based on the KML string format. Rather than copy all of the
values into new "Latitude" and "Longitude" columns, I would rather
extract the relevant values from the existing Geometry strings, if
possible.

I have searched in many places with a variety of query terms for the
solution, but I can't seem to find the relevant code. Though the data
in the table aren't part of a KML file anymore, is it still possible
to parse the coordinates string into usable Google Maps coordinates?

In the meantime, I'll try to write some Javascript that will extract
the numbers as strings based on their positions relative to the
brackets and commas, but if there's a simpler, more semantic
technique, I would appreciate knowing it! Thanks in advance for any
assistance.

geoco...@gmail.com

unread,
Aug 2, 2011, 3:53:59 PM8/2/11
to Google Maps JavaScript API v3
On Aug 2, 8:49 am, "Matthew W. Shepherd"
<matthew.w.sheph...@gmail.com> wrote:
> I'll preface this by noting that I am still early in the stages of
> learning Javascript, but I have so far been relatively successful with
> the Google Maps API. I'm also leaving out extensive code because I
> feel that this is simple enough to preclude lengthy examples.
>
> I'm using the Maps API in tandem with Fusion Tables to map various
> placemarks. The data came from an imported KML file, so the
> coordinates of each placemark are rendered in the table as Geometry
> strings in the form "<Point><coordinates>longitude, latitude,
> altitude</coordinates></Point>". The Google Maps Visualization layer
> renders properly with all of the placemarks.
>
> The problem I'm running into is that I would like to use these
> coordinates to define the position of an info window corresponding to
> a selected data row. I can't figure out an elegant way to define lat
> and lng based on the KML string format. Rather than copy all of the
> values into new "Latitude" and "Longitude" columns, I would rather
> extract the relevant values from the existing Geometry strings, if
> possible.
>
> I have searched in many places with a variety of query terms for the
> solution, but I can't seem to find the relevant code. Though the data
> in the table aren't part of a KML file anymore, is it still possible
> to parse the coordinates string into usable Google Maps coordinates?

Yes. I have a modified version of geoxml3 that allows parsing of kml
strings into google maps objects (markers, polylines, polygons).

One example of using it is:
http://www.geocodezip.com/geoxml3_test/v3_FusionTables_Watershed_Stewards_Map_sidebar2.html

-- Larry
Reply all
Reply to author
Forward
0 new messages