My favorites
▼
|
Sign in
pocketnavigator
Offline Turn By Turn Direction On windows mobile (using exported data from desktop app)
Project Home
Downloads
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
PocketDashboard
/
MapUtillityClasses
/
MapsUtils.cs
r31
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Net;
namespace MapUtilities
{
public class MapsUtils
{
string key;
public MapsUtils(string key)
{
}
public MapsUtils()
{
/*this is demo key*/
key = "ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSsTL4WIgxhMZ0ZK_kHjwHeQuOD4xQJpBVbSrqNn69S6DOTv203MQ5ufA";
}
public string GetStaticMapUrl(string latitude, string longitude,int zoom,int width,int height)
{
string url = "http://maps.google.com/staticmap?center=" + latitude + "," + longitude + "&zoom=" + zoom + "&size=" + width + "x" + height + "&sensor=false&key=" + key;
return url;
}
double toRad(double value)
{
return value * Math.PI / 180;
}
double toDeg(double value)
{
return value * 180 / Math.PI;
}
double toBearing(double value)
{
return (toDeg(value) + 360) % 360;
}
public double GetBearing(LatLng GLatLng1, LatLng GLatLng2)
{
double lat1 = GLatLng1.Lat;
double lon1 = GLatLng1.Lng;
double lat2 = GLatLng2.Lat;
double lon2 = GLatLng2.Lng;
lat1 = toRad(lat1);
lat2 = toRad(lat2);
double dLon = toRad(lon2 - lon1);
double y = Math.Sin(dLon) * Math.Cos(lat2);
double x = Math.Cos(lat1) * Math.Sin(lat2) - Math.Sin(lat1) * Math.Cos(lat2) * Math.Cos(dLon);
return toBearing( Math.Atan2(y, x));
}
public double GetDistanceBetweenPoints(double latitudes1, double longitudes1, double latitudes2, double longitudes2)
{
double R = 6371; // km
double dLat = toRad(latitudes2 - latitudes1);
double dLon = toRad(longitudes1 - longitudes2);
//latitudes1 = toRad(latitudes1);
//latitudes2 = toRad(latitudes2);
double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
Math.Cos(toRad(latitudes1)) * Math.Cos(toRad(latitudes2)) *
Math.Sin(dLon / 2) * Math.Sin(dLon / 2);
double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
double d = R * c;
return Math.Abs( d);
}
public double GetDistanceBetweenPoints(LatLng p1, LatLng p2)
{
return GetDistanceBetweenPoints(p1.Lat, p1.Lng, p2.Lat, p2.Lng);
}
public double GetDistanceBetweenLineAndPointInUnknownUnit(double x1, double y1, double x2, double y2, double x0, double y0)
{
double distance = Math.Abs((x2 - x1) * (y1 - y0) - (x1 - x0) * (y2 - y1)) / Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1)*(y2 - y1));
return distance;
}
public double GetDistanceBetweenLineAndPointInUnknownUnit(LatLng LinePoint1 ,LatLng LinePoint2,LatLng Point)
{
/**/
PixelPoint pxLinePoint1 = FlatenMyLocation(LinePoint1);
PixelPoint pxLinePoint2 = FlatenMyLocation(LinePoint2);
PixelPoint pxPoint = FlatenMyLocation(Point);
return GetDistanceBetweenLineAndPointInUnknownUnit(pxLinePoint1.x, pxLinePoint1.y, pxLinePoint2.x, pxLinePoint2.y, pxPoint.x, pxPoint.y);
}
PixelPoint FlatenMyLocation(LatLng loc)
{
double target_y = LatToY(loc.Lat );
double target_x = LongToX(loc.Lng);
return new PixelPoint(target_x, target_y);
}
double LatToY(double lat)
{
double offset = 268435456;
double radius = offset / Math.PI;
return (offset - radius * Math.Log((1 + Math.Sin(lat * Math.PI / 180)) / (1 - Math.Sin(lat * Math.PI / 180))) / 2);
}
double LongToX(double lon)
{
double offset = 268435456;
double radius = offset / Math.PI;
return (offset + radius * lon * Math.PI / 180);
}
public bool isPixelWithInRect(PixelPoint p, double width, double height)
{
if ((p.x >= 0 && p.x < width) && (p.y >= 0 && p.y < height))
{
return true;
}
return false;
}
public int GetSuiatbleZoomForPoints(LatLng P1,LatLng P2, double width, double height)
{
LatLng center = new LatLng((P1.Lat + P2.Lat) / 2, (P1.Lng + P2.Lng) / 2);
int zoom = 16;
for (zoom = 16; zoom > 2; zoom--)
{
PixelPoint px1 = GetCordinateOnStaticImage(P1, center, zoom, width, height);
PixelPoint px2 = GetCordinateOnStaticImage(P2, center, zoom, width, height);
if (isPixelWithInRect(px1, width, height) && isPixelWithInRect(px2, width, height))
{
return zoom;
}
}
return zoom;
}
public PixelPoint GetCordinateOnStaticImage(LatLng Position, LatLng Center, int zoom, double width, double height)
{
return GetCordinateOnStaticImage(Position.Lat, Position.Lng, Center.Lat, Center.Lng, zoom, width, height);
}
public PixelPoint GetCordinateOnStaticImage(double latitude, double longitude, double centerLat, double centerLang, int zoom,double width,double height)
{
long val = 1 << ((21 - zoom));
double target_y = LatToY(latitude);
double target_x = LongToX(longitude);
double delta_x = (((target_x - LongToX(centerLang))) / (val));
double delta_y =(((target_y - LatToY(centerLat)) )/ (val));
double marker_x = (width/2) + delta_x;
double marker_y = (height/2) + delta_y;
PixelPoint p = new PixelPoint(marker_x,marker_y);
return p;
}
}
}
Show details
Hide details
Change log
r2
by mark.dawn on Jan 14, 2010
Diff
First Time Check-In
Go to:
/trunk/PocketDashboard
...etDashboard/Mainform.Designer.cs
/trunk/PocketDashboard/Mainform.cs
...nk/PocketDashboard/Mainform.resx
...cketDashboard/MapUtillityClasses
...UtillityClasses/DirectionInfo.cs
...UtillityClasses/DirectionStep.cs
...ard/MapUtillityClasses/LatLng.cs
.../MapUtillityClasses/MapsUtils.cs
...MapUtillityClasses/PixelPoint.cs
...llityClasses/SerializableList.cs
...llityClasses/StaticMapOverLay.cs
...Dashboard/PocketDashboard.csproj
...oard/PocketDashboard.csproj.user
...ketDashboard/PocketDashboard.sln
...ketDashboard/PocketDashboard.suo
/trunk/PocketDashboard/Program.cs
/trunk/PocketDashboard/Properties
...board/Properties/AssemblyInfo.cs
...Properties/Resources.Designer.cs
...hboard/Properties/Resources.resx
...etDashboard/testDirectionifo.xml
/trunk/staticmaptest
/trunk/staticmaptest/ClickMap.htm
...taticmaptest/DirectionsTest.html
.../staticmaptest/Form1.Designer.cs
/trunk/staticmaptest/Form1.cs
/trunk/staticmaptest/Form1.resx
...staticmaptest/MapUtillityClasses
...UtillityClasses/DirectionInfo.cs
...UtillityClasses/DirectionStep.cs
...est/MapUtillityClasses/LatLng.cs
.../MapUtillityClasses/MapsUtils.cs
...MapUtillityClasses/PixelPoint.cs
...llityClasses/SerializableList.cs
...llityClasses/StaticMapOverLay.cs
/trunk/staticmaptest/Program.cs
/trunk/staticmaptest/Properties
...ptest/Properties/AssemblyInfo.cs
...Properties/Resources.Designer.cs
...aptest/Properties/Resources.resx
.../Properties/Settings.Designer.cs
...est/Properties/Settings.settings
...aticmaptest/StaticMapTest.csproj
.../staticmaptest/StaticMapTest.sln
.../staticmaptest/StaticMapTest.suo
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 6137 bytes, 151 lines
View raw file
Powered by
Google Project Hosting