Sunday, 15 March 2015

Google maps v3 - Draw a polygon to show photo take angle -


I'm displaying Google Maps (v3) markers in a situation where the picture was taken and the status of the subject and Line to show the direction in which the photo was taken I have also measured the distance and angle from the position of the camera.

What I am trying now is to show the scene with the camera with a triangle, which says 30 degrees towards the subject. I think there is a third grade math, but can not be detected after 25 years, I know how to draw a polygon / triangle, but in fact it is not that at the distance of the subject 30 degrees in both directions How to calculate the digits, remember the title angle.

Almost there ...

The formula below was used to use the formula (I found it necessary to change: Lat1, Lon1 and mathematics before radians.
I change this function every time to calculate a marker of pause 1 and pause 2 triangle and change the path to redraw it. / P>

The thing is now that the triangle

the question is now:

Google has the right in the West Positive and negative for the western countries.Previously (-180/180) and think that the formula needs beering in 360 degrees? Now the camera captures (75) correctly , But I have left 15 degree view instead of 15 degree angle to 15 degrees, and 15 to the right).

  function getVertex (brng) {var r = 6366.707; Var d = parseFloat (getObj ('GPSDestDistance'). Value) * 1.5 / Distance on field field / camera carrier's position lat1 = deg2rad (markerCam.getPosition (). Lat ()) var lon1 = deg2rad (markerCam.getPosition) ( ) .lng ()) var lat2 = Math.asin (Math.sin (lat1) * Math.cos (d / R) + Math.cos (lat1) * Math.sin (d / R) * Math.cos (Brng )); Var lon2 = lon1 + Math.atan2 (Math.sin (brng) * Math.sin (d / R) * Math Kos (Late 1), Math Kaos (D / R) - Math. Sin (lat1) * Math Sin Lat2)); Lat2 = rad2deg (lat2) lon2 = rad2deg (lon2) var pos = new google.maps.LatLng (lat2, lon2) return pauses; } Function camera view (angle) {var brng = deg2rad (parseFloat (getObj ('GPS dashbearing').)); // Get the title from the form if (brng & lt; 0) {// brng = Math.round (-brng / 360 + 180)} var pos1 = markerCam.getPosition (); Var pos2 = getVertex (beng-angle); Var pos3 = getVertex (beng + angle); Var path = [pause 1, pause 2, pause 3]; Poly.setPath (path); } Function deg2rad (x) {return x * (Math.pi / 180); } Function rad2deg (x) {return x * (180 / Math.PI); }    

To get an endpoint latitude and longitude (latitude 2, loan 2) Formula initial position (lat1, lon1) (also in radians), range (d), radius of earth (r) and bearing (brandy): in radians

  lat2 = Math .asin (Mathematics sin (lat1) * math kos (d / r) + math kos (lat 1) * math.sein (d / r) * math kos (brng)); Var lon2 = lon1 + Math.atan2 (Math.sin (brng) * Math.sin (d / R) * Math Kos (Let1), Math Kaos (D / R) -Math. (Let1) * Math Sin ( Lat2));   

Your starting point will be one of the points of the triangle polygon. The second two can be found using this code snippet, which is your effect +/- 15 degrees (for example 30 degree triangle) and a boundary which is completely dependent on how big you want the triangle.

No comments:

Post a Comment