-
Notifications
You must be signed in to change notification settings - Fork 2
/
GoogleMap.as
54 lines (49 loc) · 1.52 KB
/
GoogleMap.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package
{
import flash.net.URLRequest;
import flash.net.navigateToURL;
public class GoogleMap
{
public static function open(latitiude:*,longitude:*,title:String=''):void
{
openMap(latitiude+","+longitude,title);
}
/**Pass the latitude and longitude togather as locationString and seperate them by , : 3.4324324,5.4324343*/
public static function openMap(locationString:String,locationTitle:String=''):void
{
if(DevicePrefrence.isPC())
{
navigateToURL(new URLRequest("https://www.google.com/maps/@"+locationString+",15z"));
}
else if(DevicePrefrence.isIOS())
{
navigateToURL(new URLRequest("maps:q="+locationString));
}
else
{
navigateToURL(new URLRequest("geo://"+locationString+"?z=1&q="+locationString+" ("+locationTitle+")"));
}
}
/**returns in kilometers */
public static function CalculationByDistance(startLat:Number,startLon:Number,endLat:Number,endLon:Number):Number
{
var Radius:int = 6371;// radius of earth in Km
var dLat:Number = toRadians(endLat - startLat);
var dLon:Number = toRadians(endLon - startLon);
var a:Number = Math.sin(dLat / 2) * Math.sin(dLat / 2)
+ Math.cos(toRadians(startLat))
* Math.cos(toRadians(endLat)) * Math.sin(dLon / 2)
* Math.sin(dLon / 2);
var c:Number = 2 * Math.asin(Math.sqrt(a));
return Radius * c;
}
private static function toDegrees(radians:Number):Number
{
return radians * 180/Math.PI;
}
private static function toRadians(degrees:Number):Number
{
return degrees * Math.PI / 180;
}
}
}