[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Finding a latitude and longitude on a circle drawn with a specific radius on google maps

Posted on 2009-02-21
12
Medium Priority
?
1,031 Views
Last Modified: 2013-11-10
Hai,

I am working in a project where I will pick a point on google map by clicking somewhere on the map and draw a circle with a radius, say 1 mile. So a later if a user enters some latitude and longitude, I will have to say whether it falls within the circle or not. I am trying to do this with google maps api. I am not able to focus on any logic in particular. My problem is finding if the given coodinate or latitude or longitude is within the circle or not. I am unable to think of anything that will help. Thank you for your time.

0
Comment
Question by:sreekanthvasireddy
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 9

Expert Comment

by:Ken Fayal
ID: 23699063
There are a lot of good resources online to read concerning this.  Here is one I can tell you about first,

http://www.free-zipcodes.com/

More to come.
0
 
LVL 9

Expert Comment

by:Ken Fayal
ID: 23699071
0
 
LVL 9

Expert Comment

by:Ken Fayal
ID: 23699090
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 9

Expert Comment

by:Ken Fayal
ID: 23699097
Then of course, you have a source right from Google.

http://code.google.com/apis/maps/index.html
0
 
LVL 1

Author Comment

by:sreekanthvasireddy
ID: 23699599
Hai KaptainKenbo,

Thanks for your prompt replies. I have gone through all of those, but could not find what I was looking for. Maybe, I have not been clear enough. Let me explain with an example.

Suppose, I a circle at a zoom level of 6. which is pretty high up in the sky. The area covered would be more than what I would cover with the circle of the same radius drawn at say 14, meaning closer to the ground. I would have to figure out some way to accommodate this variance. Maybe, I would need to get the coordinates on the circumference of circle. I don't know. I am just thinking aloud. Please let me know what you think. Thanks
0
 
LVL 13

Expert Comment

by:imarshad
ID: 23841929
>>Suppose, I a circle at a zoom level of 6. which is pretty high up in the sky. The area covered would
>>be more than what I would cover with the circle of the same radius drawn at say 14, meaning
>>closer to the ground.
Well it all depends upon the circle you have drawn. If you have drawn a circle of 1 mile it will be the same even if you are watching from 1000meters above or on ground level.

In your case you donot need the circumference of the circle but only the center points of the circle and the radius of the circle. As an example your circle center coordinates are long0,lat0 and your circle has a radius of "t" meters. Now the user enters the latitude & longitude as lat1 and long1 and you need to check if the points are within your circle or not. Simply use a distance formula between the center coordinates and the coordinates entered. Then compare it with the radius. If the distance between the coordinates is less then the radius then the point lie within the circle else they are out of the circle.....
0
 
LVL 13

Expert Comment

by:imarshad
ID: 23841992
As far as calculating distance between lat1,long1 and lat0, long0 is concerned you can use the following formula

Haversine formula:
      
R = earths radius (mean radius = 6,371km)
”lat = lat2 lat1
”long = long2 long1
a = sin²(”lat/2) + cos(lat1).cos(lat2).sin²(”long/2)
c = 2.atan2(a, (1a))
d = R.c  

Spherical law
of cosines:       d = acos(sin(lat1).sin(lat2)+cos(lat1).cos(lat2).cos(long2long1)).R

Visit the following site for full formulas
http://www.movable-type.co.uk/scripts/latlong.html
0
 
LVL 13

Expert Comment

by:imarshad
ID: 23842027
Formatting of formulas in above post got ruined.... So trying it in code view... Anyway you can always visit the site posted above to get the formula.....
Haversine formula:
	
 
R = earths radius (mean radius = 6,371km)
”lat = lat2 lat1
”long = long2 long1
a = sin²(”lat/2) + cos(lat1).cos(lat2).sin²(”long/2)
c = 2.atan2(a, (1a))
d = R.c
 
(Note that angles need to be in radians to pass to trig functions).
 
Spherical law
of cosines: 	d = acos(sin(lat1).sin(lat2)+cos(lat1).cos(lat2).cos(long2long1)).R

Open in new window

0
 
LVL 13

Assisted Solution

by:imarshad
imarshad earned 2000 total points
ID: 23842044
Still not working in code view... So visit the http://www.movable-type.co.uk/scripts/latlong.html site for the distance formulas....
0
 
LVL 1

Accepted Solution

by:
sreekanthvasireddy earned 0 total points
ID: 23842563
Thank you imarshad. I understand your viewpoint. I am going to check it out and let you know.
0
 
LVL 32

Expert Comment

by:Kamran Arshad
ID: 23886798
sreekanthvasireddy you should close this question by accepting the helpful answer.....
0
 
LVL 13

Expert Comment

by:imarshad
ID: 23886823
If my suggestion was helpful then you should accept my answer.....
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…
Suggested Courses
Course of the Month18 days, 17 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question