javascript - conversion latitude/longitude into distance -
My problem is a bit difficult, sorry if my question is not quite clear.
i Use the GoogleMap v3 API user can click on the map to make a mark, if he clicks on the mark, I give the latitude; Fans in an information (it is done and it is fine)
Things to try: The user can give the dimension (km / mi) and I have to draw a rectangle of the given size (Make the mark to be the middle of the area, make the shoud). Problems coming from laslang or range are only latitude and amp; Longitude So I try to change it.
Here is the main part of the code.
// latitude // 1 ° lat = 111,11 km // For me: 1 km = 0.00 9 00 // Illustration // 1 ° Light = 111,11 km * Cos Latitude / For me: 1 km = ((1 / Mathematics (latitude)) /111.11) var myBounds = New Array (); var Langkam = 5; Var largkm = 2; MyBounds [0] = New google.maps.LatLngBounds (new google.maps.LatLng (positionmarqueur.lat () - (0.009 * longcam), positionmarqueur.lng () - (Math.bas (((((1 / Math.cos (Positionmarqueur.lat () - (0.009 * Longimi))) /111.11))*Largkm), New google.maps.LatLng (positionmarqueur.lat (+) + (0.009 * longkm), positionmarqueur.lng () + (Monastery) EB (((1 / mathikos (positionmarqueur.lat () + (0.009 * long km))) /111.11))*largkm))) Var overlay 1 = new google.maps.Rectangle ({map: map, borders: My bounce [0], stroke color: "green", stroke white: 1}) var langkam = 10; var largkm = 10; my bounce [1] = new google.maps.LatLngBounds (new google.maps.LatLng ( positionmarqueur.lat () - (0.009 * longcomp), positionmarqueur.lng () - (Math.aba (((1 / Math.cos (Positionmarqueur.lat () - (0.009 * Longimi))) /111.11))*Largkm), New google.maps.LatLng (positionmarqueur.lat () + (0.009 * longkm) , Positionmarqueur.lng () + (Math Ab ((((1 / mathakos (positionmarqueur.lat () + (0.009 * long km))) /111.11))*largkm))); Var Overlay 2 = New google.maps Rectangle ({map: map, borders: my bounce [1], stroke color: "blue", strokewit: 1}); This shoud draws a 5,2 rectanle and 10,10 rectangle (well, a 10km square) (for information: var positionmarqueur = latLng; code above)
If I look at the result: the first rectangle is visible more than 50/20 km (have I made a mistake when I am dividing it with a 10 factor? I am not very good in mathematics, but it Looks correct).
Second time .... just look like 200 * 40 km rectangular ....
So where's the problem? Is the formulas wrong? Or am I just mute and I miss something?
Thin.
use of algorithm
var largkm = 5, longkm = 10 ; Var bound = new google.maps.LatLngBounds (new google.maps.LatLng (positionmarqueur.lat) - ((largkm / 2) /110.54), positionmarqueur.lng () - ((longkm / 2) / (Math.cos ( Positionmarqueur.lat ()) * 111.32), new google.maps.LatLng (positionmarqueur.lat () + ((largkm / 2) /110.54), positionmarqueur.lng () + ((longkm / 2) / (Math. Cos (positionmarqueur.lat ()) * 111.32)))); ( Note: I'm dividing the rectangle size by 2 because we are setting boundaries from the center ) < Strong> demo update You should use Google Geometry Library, which uses Google Maps to launch So, the change will be correct. ( You will need to change the URL of the Google API for http://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false ) The more specific you should use the method
var rectbounds = new google.maps.LatLngBounds (spherical.computeOffset (spherical.computeOffset (positionmarqueur, longkm * 1000 / 2), -90), large scale * 1000 / 2.0, spherical.computeoffset (spherical.computeoffset (positionmarqueur, longkm * 1000/2, 90), largkm * 1000 / 2,180)); update demo on
( to * 1000 ) to change the meter as it is < Expected from Code> computeoffice method )
Comments
Post a Comment