Google Maps Javascript API V3 Geometry Library Documentation?

3,739 views
Skip to first unread message

geoco...@gmail.com

unread,
Jan 5, 2011, 1:20:47 AM1/5/11
to Google Maps JavaScript API v3
I just saw the neat API V3 Geometry Library

http://code.google.com/apis/maps/documentation/javascript/geometry.html

The documentation seems a little thin right now. Some questions:
- What units do computeLength and computeDistanceBetween return their
results in?
(I assumed meters, and that loooks to be correct)
- Is there anyway to change those units?

- Does computeLength take a "path" an array of latlng objects (it
doesn't seem to, how do we use it?
It says this: You may instead use computeLength() to calculate the
length of a given path if you have several locations

- Does computeArea take a path? Will it work on a google.maps.Polygon?

The examples don't include the length or area methods.

Thanks,
Larry

Nianwei Liu

unread,
Jan 5, 2011, 7:26:31 AM1/5/11
to Google Maps JavaScript API v3
This is great news. I was wondering if there is a plan to expand this
library to include more standard computational geometry functions in,
such as intersect, hittest etc in? Since it is treated a separate lib
to load, it's size probably is a less concern that the core. Also, I
assuming even it is specified in the bootstrap code, it will still
loaded afterwards (i.e. won;t not increase the startup time)?


On Jan 5, 1:20 am, "geocode...@gmail.com" <geocode...@gmail.com>
wrote:
> I just saw the neat API V3 Geometry Library
>
> http://code.google.com/apis/maps/documentation/javascript/geometry.html
>

Nianwei Liu

unread,
Jan 5, 2011, 3:55:28 PM1/5/11
to Google Maps JavaScript API v3
Looked into reference and tried a few things.

> > - Does computeLength take a "path" an array of latlng objects (it
> > doesn't seem to, how do we use it?
> > It says this: You may instead use computeLength() to calculate the
> > length of a given path if you have several locations

It does, just use the poly.getPath().getArray() and pass in.


> > - Does computeArea take a path? Will it work on a google.maps.Polygon?
It does. For multi-parts polygon, you may need to calculate individual
parts and subtract rings or add together. For simple ones, just
poly.getPath().getArray().
The documentation says it requires a closed loop, but it looks like it
can work either way, i.e. you do not need push the first point into
the array.

I did noticed a problem, the API code used a constant 1.0E-6 to decide
the sign of the smaller triangle area, but that number is way too big,
so the function only works if you are at a small zoom level like
county wide, once you zoom to street level, it returns 0 which is
apparently wrong. I'll report.

test link: http://gmaps-utility-gis.googlecode.com/svn/trunk/v3test/geom/measure.html



Chris Broadfoot

unread,
Jan 5, 2011, 7:29:00 PM1/5/11
to google-map...@googlegroups.com
Hi Larry,

Check the docs here:

You can change units by specifying the 'radius' parameter from the default. For example, if you want to perform calculations in miles, specify the earth's radius as 3963.19 (only an approximation, of course)

computeLength takes Array.<LatLng>, as does computeArea, but the path must be closed.

computeArea does not work on a google.maps.Polygon, you'll need to call getPath/getPaths and pass through a single array of LatLngs.

Chris


--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.


geoco...@gmail.com

unread,
Jan 5, 2011, 7:53:39 PM1/5/11
to Google Maps JavaScript API v3
On Jan 5, 4:29 pm, Chris Broadfoot <c...@google.com> wrote:
> Hi Larry,
>
> Check the docs here:http://code.google.com/apis/maps/documentation/javascript/reference.h...

Awsome. Didn't see that last night (didn't think to look for it in
the regular v3 reference...)

>
> You can change units by specifying the 'radius' parameter from the default.
> For example, if you want to perform calculations in miles, specify the
> earth's radius as 3963.19 (only an approximation, of course)
>
> computeLength takes Array.<LatLng>, as does computeArea, but the path must
> be closed.
>
> computeArea does not work on a google.maps.Polygon, you'll need to call
> getPath/getPaths and pass through a single array of LatLngs.

Thank you (and thank you for the time you and the other google
engineers spend answering questions here)/
With the reference I could have answered my own questions.

-- Larry

>
> Chris
>
> On Wed, Jan 5, 2011 at 5:20 PM, geocode...@gmail.com
> <geocode...@gmail.com>wrote:
>
>
>
> > I just saw the neat API V3 Geometry Library
>
> >http://code.google.com/apis/maps/documentation/javascript/geometry.html
>
> > The documentation seems a little thin right now.  Some questions:
> > - What units do computeLength and computeDistanceBetween return their
> > results in?
> > (I assumed meters, and that loooks to be correct)
> > - Is there anyway to change those units?
>
> > - Does computeLength take a "path" an array of latlng objects (it
> > doesn't seem to, how do we use it?
> > It says this: You may instead use computeLength() to calculate the
> > length of a given path if you have several locations
>
> > - Does computeArea take a path? Will it work on a google.maps.Polygon?
>
> > The examples don't include the length or area methods.
>
> >  Thanks,
> >  Larry
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Google Maps JavaScript API v3" group.
> > To post to this group, send email to
> > google-map...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-maps-js-a...@googlegroups.com<google-maps-js-api-v3%2B­unsub...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/google-maps-js-api-v3?hl=en.- Hide quoted text -
>
> - Show quoted text -

Chris Broadfoot

unread,
Jan 5, 2011, 8:13:54 PM1/5/11
to google-map...@googlegroups.com
On Thu, Jan 6, 2011 at 11:53 AM, geoco...@gmail.com <geoco...@gmail.com> wrote:
Thank you (and thank you for the time you and the other google
engineers spend answering questions here)/

No problem Larry.

I know you don't check your gmail account, so I will have to extend my gratitude publicly. Thank *you* for the time you spend on our forums answering questions!

Chris
Reply all
Reply to author
Forward
0 new messages