This repository has been archived by the owner on Nov 24, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
app-provider.js
129 lines (103 loc) · 3.07 KB
/
app-provider.js
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
/*jslint maxerr:1000 */
var my = {
geoNames : require('./GeoProviders/geonames_geoprovider'),
basicGeo : require('./GeoProviders/bencoding_geoprovider'),
google : require('./GeoProviders/google_geoprovider'),
activeProviderName : 'geonames'
};
(function () {
var win = Ti.UI.createWindow({
backgroundColor: '#fff', title: 'Ti.GeoProviders',
barColor:'#000',fullscreen:false
});
var mapView = Ti.Map.createView({
top:80, bottom:0, width:Ti.UI.FILL,userLocation:false
});
win.add(mapView);
var lookup = {
updateDataLabel : function(providerType){
my.activeProviderName = providerType;
if(providerType=='geonames'){
ccLabel.visible = true;
ccLabel.text ="data by GeoNames.org";
}
if(providerType=='google'){
ccLabel.visible = true;
ccLabel.text ="data by Google";
}
if(providerType=='basicgeo'){
ccLabel.visible = false;
}
},
updateProvider : function(providerType){
Ti.API.info('Adding provider: ' + providerType);
if(providerType == 'geonames'){
my.provider = my.geoNames;
//Add your user key
my.provider.addKey('demo');
}
if(providerType == 'google'){
my.provider = my.google;
}
if(providerType == 'basicgeo'){
my.provider = my.basicGeo;
}
//Add your GPS Access Reason
my.provider.addPurpose('Demo of Geo Provider');
//Update our label
lookup.updateDataLabel(providerType);
},
addToMap: function(lat,lng,title){
var pin = Ti.Map.createAnnotation({
latitude:lat,longitude:lng,
title:title
});
mapView.addAnnotation(pin);
var region = {latitude:lat,longitude:lng,animate:true,
latitudeDelta:0.04, longitudeDelta:0.04};
mapView.setLocation(region);
},
onSuccess : function(e){
if(!e.found){
alert("Unable to find your location");
return;
}
//Generate the address
var title = my.provider.generateAddress(e);
//Add to the map
lookup.addToMap(e.latitude,e.longitude,title);
},
onError: function(e){
Ti.API.info(JSON.stringify(e));
alert("Error finding your location, see console for details");
}
};
var findButton = Ti.UI.createButton({
title:'Find Current Location', left:10, right:10,top:40,height:40
});
win.add(findButton);
findButton.addEventListener('click',function(e){
if(!Ti.Network.online){
alert("You must be online to run this recipe");
return;
}
my.provider.getCurrentAddress(lookup.onSuccess,lookup.onError);
});
var ccLabel = Ti.UI.createLabel({
left:20, right:20, height:40, color:'#000',
textAlign:'right', font:{fontSize:12, fontWeight:'bold'},
bottom:0, text:'Data Provided by GeoNames.org'
});
win.add(ccLabel);
ccLabel.addEventListener('click',function(e){
if(my.activeProviderName == 'geonames'){
Ti.Platform.openURL("http://geonames.org");
}
if(my.activeProviderName == 'google'){
Ti.Platform.openURL("http://developers.google.com/maps");
}
});
//Set defaults
lookup.updateProvider(my.activeProviderName);
win.open({modal:true});
})();