mapsplugin / cordova-plugin-googlemaps

Google Maps plugin for Cordova
Apache License 2.0
1.66k stars 918 forks source link

How can I know if a marker is contained within a circle? #2268

Closed YeisonVelez11 closed 6 years ago

wf9a5m75 commented 6 years ago

This is just mathematic in junior high school.

https://github.com/mapsplugin/cordova-plugin-googlemaps/issues/2211#issuecomment-380546469

YeisonVelez11 commented 6 years ago

@wf9a5m75 Excuse my ignorance, but it has not been clear to me. could you help me please? How should that piece of code be?

var circleArea=circle.getBounds(); circleArea.contains({lat:xxx, lng:xxx}) //coordinates to evaluate if is inside of the circle.. //circle.getCenter() and marker.getPosition(). ???

wf9a5m75 commented 6 years ago

Did you really read my comment, and you don't understand? Are you a junior school student? If yes, I give you exact code. If you are adult, you should use your brain.

YeisonVelez11 commented 6 years ago

@wf9a5m75 I think it's a disrespectful comment. I'm asking you with much respect. We do not all understand and we have the same knowledge as you. and I bet you that if I had your knowledge I would not be arrogant. for your information I am new to this topic of google maps, I have little experience programming and I do not understand very well what I should do. If it makes you feel good, I am what you want to believe it to be, but it is not my fault that I do not understand you. and yes, I read your answer but I'm not sure what I should do.

wf9a5m75 commented 6 years ago

OKAY, I'm really disappointed your comment. This is NOT programming skill, this is junior school math question.

Here are some hints:


When you create a circle, you need to specify radius and center properties.

var R = 50; // 50meter
var centerPos = {lat: ..., lng: ...};

// v2.3.x style
var circle = map.addCircle({
  center: centerPos,
  radius: R
});

If your circle is moving, you can get both values through getRadius() and getCenter().

var R = center.getRadius();
var centerPos = center.getCenter();

So if a marker is exactly on the edge of the circle, the distance between center and marker is distance = R.

dr

If the marker is inside the circle, the distance between center and marker is distance < R. d1


If the marker is outside the circle, the distance between center and marker is distance > R. d2


As I commented below in previous comment, you can calculate distance between center and marker position.

Calculating distance between A and B is https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.3.0/class/utilities/geometry/spherical/computeDistanceBetween/README.md

So what you should?

wf9a5m75 commented 6 years ago

Did you resolve your question?

YeisonVelez11 commented 6 years ago

Thanks, I think I have it.

YeisonVelez11 commented 6 years ago

I apologize for the problems, and misunderstandings. I am very bad with maths I must admit it.

wf9a5m75 commented 6 years ago

Enjoy the maps plugin.