How to check if a given marker is inside a area

3,878 views
Skip to first unread message

lucaswxp

unread,
Feb 17, 2011, 4:44:46 AM2/17/11
to Google Maps JavaScript API v3
Hello everybody o/
I know that this is more a math question than gmap, but I suppose that
someone already pass through this =)

In my map, I have circle (actually I have several of them, but this
not change the question), like this:
http://code.google.com/intl/pt-BR/apis/maps/articles/mvcfun/step6.html

How do I know if a marker (with latitude X and longitude Y) is inside
this circle?

Sorry for the bad english, I'm brazillian =p

Martin Matysiak

unread,
Feb 17, 2011, 5:26:02 AM2/17/11
to google-map...@googlegroups.com
Your circle object has the getRadius() method. Because of that I think the simplest way to check if a location is in- or outside the circle would be calculating the distance between location and the center of your circle (see geometry library) and compare the calculated distance to your circle radius.

Best regards,
Martin Matysiak

Paulo Fernandes

unread,
Mar 2, 2011, 7:50:36 PM3/2/11
to google-map...@googlegroups.com, Martin Matysiak, luca...@gmail.com
I think that I solved this issue


If you zoom in the border of the circle and click, maybe you get the "INSIDE" message, I think that is a bug on circle radius size


--
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,
Mar 2, 2011, 7:58:46 PM3/2/11
to Google Maps JavaScript API v3
On Mar 2, 4:50 pm, Paulo Fernandes <paulofernande...@gmail.com> wrote:
> I think that I solved this issue
>
> http://www.pjtecnologia.com.br/maps/exemplos/check-lat-lng-is-inside-...
>
> If you zoom in the border of the circle and click, maybe you get the
> "INSIDE" message, I think that is a bug on circle radius size

How about irregular polygons:
http://www.geocodezip.com/geoxml3_test/v3_collection-map2e.html
(does point in polygon analysis with the point from the geocoded
address)

-- Larry


>
> Paulo Fernandeshttp://www.google.com/profiles/paulofernandesjrhttp://twitter.com/paulofernandesj
> +55 11 9797-5974
>
> On Thu, Feb 17, 2011 at 8:26 AM, Martin Matysiak
> <kaktus...@googlemail.com>wrote:
>
>
>
> > Your circle object has the getRadius() method. Because of that I think the
> > simplest way to check if a location is in- or outside the circle would be
> > calculating the distance between location and the center of your circle
> > (see geometry library<http://code.google.com/intl/en/apis/maps/documentation/javascript/geo...>)
> > and compare the calculated distance to your circle radius.
>
> > Best regards,
> > Martin Matysiak
> >  homepage <https://martin-matysiak.de/> | blog<http://blog.martin-matysiak.de/>
>
> > --
> > 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.- Hide quoted text -
>
> - Show quoted text -

Paulo Fernandes

unread,
Mar 2, 2011, 8:04:58 PM3/2/11
to google-map...@googlegroups.com
I didn't understand Larry

geoco...@gmail.com

unread,
Mar 2, 2011, 8:11:48 PM3/2/11
to Google Maps JavaScript API v3
On Mar 2, 5:04 pm, Paulo Fernandes <paulofernande...@gmail.com> wrote:
> I didn't understand Larry

Your example does circles only. The link I provided does point in
polygon analysis for an arbitrary shaped polygon (in that case the
trash pick up regions). Although the example is no where near as
simple as yours.

-- Larry

>
> Paulo Fernandeshttp://www.google.com/profiles/paulofernandesjrhttp://twitter.com/paulofernandesj
> +55 11 9797-5974
>
> On Wed, Mar 2, 2011 at 9:58 PM, geocode...@gmail.com
> <geocode...@gmail.com>wrote:
>
>
>
> > How about irregular polygons:
> >http://www.geocodezip.com/geoxml3_test/v3_collection-map2e.html
> > (does point in polygon analysis with the point from the geocoded
> > address)- Hide quoted text -

Paulo Fernandes

unread,
Mar 3, 2011, 8:53:09 AM3/3/11
to google-map...@googlegroups.com, geoco...@gmail.com
Ok

But this is a bug on API, right?

geoco...@gmail.com

unread,
Mar 3, 2011, 9:21:12 AM3/3/11
to Google Maps JavaScript API v3
On Mar 3, 5:53 am, Paulo Fernandes <paulofernande...@gmail.com> wrote:
> Ok
>
> But this is a bug on API, right?

I don't know. I didn't investigate it at all. Detecting whether or
not a geographic point is within a circle is a special case of a
general point-in-polygon algorithm.

-- Larry


>
> Paulo Fernandeshttp://www.google.com/profiles/paulofernandesjrhttp://twitter.com/paulofernandesj
> +55 11 9797-5974
>
> On Wed, Mar 2, 2011 at 10:11 PM, geocode...@gmail.com
> <geocode...@gmail.com>wrote:
Reply all
Reply to author
Forward
0 new messages