-
Notifications
You must be signed in to change notification settings - Fork 84
/
GeoUrlActivity.java
97 lines (90 loc) · 2.51 KB
/
GeoUrlActivity.java
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
package de.blau.android;
import java.io.Serializable;
import java.util.Locale;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import de.blau.android.util.GeoMath;
/**
* Start vespucci with geo: URLs.
* see http://www.ietf.org/rfc/rfc5870.txt
*/
public class GeoUrlActivity extends Activity {
public static final String GEODATA = "de.blau.android.GeoUrlActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
protected void onStart() {
super.onStart();
Uri data = getIntent().getData();
Log.d("GeoURLActivity",data.toString());
Intent intent = new Intent(this, Main.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_CLEAR_TOP);
String[] query = data.getSchemeSpecificPart().split("\\?"); // used by osmand likely not standard conform
if (query != null && query.length >= 1) {
String[] params = query[0].split(";");
if (params != null && params.length >= 1) {
String[] coords = params[0].split(",");
boolean wgs84 = true; // for now the only supported datum
if (params.length > 1) {
for (String p:params) {
if (p.toLowerCase(Locale.US).matches("crs=.*")) {
wgs84 = p.toLowerCase(Locale.US).matches("crs=wgs84");
Log.d("GeoUrlActivity","crs found " + p + ", is wgs84 is " + wgs84);
}
}
}
if (coords != null && coords.length >= 2 && wgs84) {
try {
double lat = Double.valueOf(coords[0]);
double lon = Double.valueOf(coords[1]);
if (lon >= -180 && lon <= 180 && lat >= -GeoMath.MAX_LAT && lat <= GeoMath.MAX_LAT) {
GeoUrlData geoData = new GeoUrlData();
geoData.setLat(lat);
geoData.setLon(lon);
intent.putExtra(GEODATA, geoData);
}
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
startActivity(intent);
finish();
}
public static class GeoUrlData implements Serializable {
private static final long serialVersionUID = 2L;
private double lat;
private double lon;
/**
* @return the lat
*/
public double getLat() {
return lat;
}
/**
* @param lat the lat to set
*/
public void setLat(double lat) {
this.lat = lat;
}
/**
* @return the lon
*/
public double getLon() {
return lon;
}
/**
* @param lon the lon to set
*/
public void setLon(double lon) {
this.lon = lon;
}
}
}