Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Commit bf3b738

Browse files
committed
add javadoc
1 parent 36cc735 commit bf3b738

16 files changed

Lines changed: 313 additions & 54 deletions

File tree

osmunda-demo/src/main/java/moe/sunjiao/osmundademo/fragment/ForwardFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ForwardFragment : Fragment() {
5454
Log.i(TAG, "start search")
5555
val keyWord = place_name.text.toString()
5656
val database: SQLiteDatabase = getDatabase()
57-
val list: List<SearchResult> = Geocoder(database).search(keyWord, 10, 0, 30.7324, 114.6589, 30.3183, 114.0588)
57+
val list: List<SearchResult> = Geocoder(database).search(keyWord, 10, 0)
5858
Log.i(TAG, "complete")
5959
for (result in list) {
6060
val address = result.toAddress()

osmunda/src/main/java/moe/sunjiao/osmunda/Osmunda.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,26 @@ import android.database.sqlite.SQLiteDatabase
55
import java.io.File
66
import java.util.*
77

8+
/**
9+
* get database, dir and list
10+
* base class of osmunda
11+
* created on 4/22/2020.
12+
*
13+
* @author Sun Jiao(孙娇)
14+
*
15+
* @param context android context where this fun is called
16+
*/
17+
818
class Osmunda(private val context: Context) {
919

1020
fun getDatabaseList() : Array<File>?{
1121
return getDatabaseDir()
1222
.listFiles { dir, name -> name.toLowerCase(Locale.ROOT).endsWith("-osmunda.sqlite") }
1323
}
1424

25+
/**
26+
* @param name name of database
27+
*/
1528
fun getDatabaseByName(name : String): SQLiteDatabase{
1629
return context.openOrCreateDatabase(getDatabaseDir().absolutePath + "/" + name + ".sqlite", 0, null)
1730
}

osmunda/src/main/java/moe/sunjiao/osmunda/geocoder/Geocoder.kt

Lines changed: 71 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,38 @@ package moe.sunjiao.osmunda.geocoder
22

33
import android.database.Cursor
44
import android.database.sqlite.SQLiteDatabase
5-
import moe.sunjiao.osmunda.model.OsmType
65
import moe.sunjiao.osmunda.model.SearchResult
76
import org.osmdroid.util.BoundingBox
87
import java.util.*
98

9+
/**
10+
* convert a name to geographic coordinates
11+
* created on 4/22/2020.
12+
*
13+
* @author Sun Jiao(孙娇)
14+
*/
15+
1016
class Geocoder(val database: SQLiteDatabase) {
1117

18+
/**
19+
* @param searchQueryOptional name of target location
20+
* @param limit number of results
21+
* @param offset number of rows to skip before query
22+
* @param maxLat max latitude of wuery range
23+
* @param maxLon max longitude of query range
24+
* @param minLat min latitude of query range
25+
* @param minLon min longitude of query range
26+
* @return list of SearchResult
27+
*/
1228
@Throws(Exception::class)
13-
fun search(
29+
fun search (
1430
searchQueryOptional: String,
15-
limit: Int,
16-
offset: Int,
17-
maxLat: Double,
18-
maxLon: Double,
19-
minLat: Double,
20-
minLon: Double
31+
limit: Int = 1,
32+
offset: Int = 0,
33+
maxLat: Double = 90.00,
34+
maxLon: Double = 180.00,
35+
minLat: Double = -90.00,
36+
minLon: Double = -180.00
2137
): List<SearchResult> {
2238
val resultList: MutableList<SearchResult> = ArrayList<SearchResult>()
2339

@@ -43,10 +59,54 @@ class Geocoder(val database: SQLiteDatabase) {
4359
return resultList
4460
}
4561

46-
fun search (searchQueryOptional: String, limit: Int, offset: Int): List<SearchResult>
47-
= search(searchQueryOptional, limit, offset, 90.00, 180.00, -90.00, -180.00)
62+
/**
63+
* @param searchQueryOptional name of target location
64+
* @param limit number of results
65+
* @param maxLat max latitude of wuery range
66+
* @param maxLon max longitude of query range
67+
* @param minLat min latitude of query range
68+
* @param minLon min longitude of query range
69+
* @return list of SearchResult
70+
*/
71+
@Throws(Exception::class)
72+
fun search (
73+
searchQueryOptional: String,
74+
limit: Int,
75+
maxLat: Double,
76+
maxLon: Double,
77+
minLat: Double,
78+
minLon: Double
79+
): List<SearchResult>
80+
= search(searchQueryOptional, limit, 0, maxLat, maxLon, minLat, minLon)
4881

49-
fun search (searchQueryOptional: String, limit: Int, offset: Int, boundingBox: BoundingBox): List<SearchResult>
82+
/**
83+
* @param searchQueryOptional name of target location
84+
* @param limit number of results
85+
* @param offset number of rows to skip before query
86+
* @param boundingBox bounding box of query range
87+
* @return list of SearchResult
88+
*/
89+
@Throws(Exception::class)
90+
fun search (
91+
searchQueryOptional: String,
92+
limit: Int,
93+
offset: Int,
94+
boundingBox: BoundingBox
95+
): List<SearchResult>
5096
= search(searchQueryOptional, limit, offset, boundingBox.latNorth, boundingBox.lonEast,boundingBox.latSouth,boundingBox.lonWest)
5197

98+
/**
99+
* @param searchQueryOptional name of target location
100+
* @param limit number of results
101+
* @param boundingBox bounding box of query range
102+
* @return list of SearchResult
103+
*/
104+
@Throws(Exception::class)
105+
fun search (
106+
searchQueryOptional: String,
107+
limit: Int,
108+
boundingBox: BoundingBox
109+
): List<SearchResult>
110+
= search(searchQueryOptional, limit, 0, boundingBox)
111+
52112
}

osmunda/src/main/java/moe/sunjiao/osmunda/geocoder/ReverseGeocoder.kt

Lines changed: 57 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,27 @@ package moe.sunjiao.osmunda.geocoder
33
import android.database.Cursor
44
import android.database.sqlite.SQLiteDatabase
55
import android.location.Location
6-
import moe.sunjiao.osmunda.model.OsmType
76
import moe.sunjiao.osmunda.model.SearchResult
87
import org.osmdroid.api.IGeoPoint
98
import org.osmdroid.util.GeoPoint
109
import java.util.*
1110

11+
/**
12+
* search place names using a geographic coordinates
13+
* created on 4/22/2020.
14+
*
15+
* @author Sun Jiao(孙娇)
16+
*/
17+
1218
class ReverseGeocoder(val database: SQLiteDatabase) {
19+
20+
/**
21+
* @param latitude latitude of target location
22+
* @param longitude longitude of target location
23+
* @param limit number of results
24+
* @param offset number of rows to skip before query
25+
* @return list of SearchResult
26+
*/
1327
@Throws(Exception::class)
1428
fun search(
1529
latitude: Double,
@@ -46,60 +60,77 @@ class ReverseGeocoder(val database: SQLiteDatabase) {
4660
return resultList
4761
}
4862

63+
/**
64+
* @param geoPoint coordinate of target location in osmdroid GeoPoint
65+
* @param limit number of results
66+
* @param offset number of rows to skip before query
67+
* @return list of SearchResult
68+
*/
4969
@Throws(Exception::class)
5070
fun search(
5171
geoPoint: GeoPoint,
5272
limit: Int = 1,
5373
offset: Int = 0
54-
): List<SearchResult> {
55-
val lat: Double = geoPoint.latitude
56-
val lon: Double = geoPoint.longitude
57-
return search(lat,lon,limit,offset)
58-
}
74+
): List<SearchResult>
75+
= search(geoPoint.latitude, geoPoint.longitude, limit, offset)
5976

77+
/**
78+
* @param iGeoPoint coordinate of target location in osmdroid IGeoPoint
79+
* @param limit number of results
80+
* @param offset number of rows to skip before query
81+
* @return list of SearchResult
82+
*/
6083
@Throws(Exception::class)
6184
fun search(
6285
iGeoPoint: IGeoPoint,
6386
limit: Int = 1,
6487
offset: Int = 0
65-
): List<SearchResult> {
66-
val lat: Double = iGeoPoint.latitude
67-
val lon: Double = iGeoPoint.longitude
68-
return search(lat,lon,limit,offset)
69-
}
88+
): List<SearchResult>
89+
= search(iGeoPoint.latitude, iGeoPoint.longitude, limit, offset)
7090

91+
/**
92+
* @param location coordinate of target location in android Location
93+
* @param limit number of results
94+
* @param offset number of rows to skip before query
95+
* @return list of SearchResult
96+
*/
7197
@Throws(Exception::class)
7298
fun search(
7399
location: Location,
74100
limit: Int = 1,
75101
offset: Int = 0
76-
): List<SearchResult> {
77-
val lat: Double = location.latitude
78-
val lon: Double = location.longitude
79-
return search(lat,lon,limit,offset)
80-
}
102+
): List<SearchResult>
103+
= search(location.latitude, location.longitude, limit, offset)
81104

105+
/**
106+
* @param latitude latitude of target location
107+
* @param longitude longitude of target location
108+
* @param limit number of results
109+
* @param offset number of rows to skip before query
110+
* @return list of SearchResult
111+
*/
82112
@Throws(Exception::class)
83113
fun search(
84114
latitude: String,
85115
longitude: String,
86116
limit: Int = 1,
87117
offset: Int = 0
88-
): List<SearchResult> {
89-
val lat: Double = latitude.toDouble()
90-
val lon: Double = longitude.toDouble()
91-
return search(lat,lon,limit,offset)
92-
}
118+
): List<SearchResult>
119+
= search(latitude.toDouble(),longitude.toDouble(),limit,offset)
93120

121+
/**
122+
* @param latitude latitude of target location
123+
* @param longitude longitude of target location
124+
* @param limit number of results
125+
* @param offset number of rows to skip before query
126+
* @return list of SearchResult
127+
*/
94128
@Throws(Exception::class)
95129
fun search(
96130
latitude: Float,
97131
longitude: Float,
98132
limit: Int = 1,
99133
offset: Int = 0
100-
): List<SearchResult> {
101-
val lat: Double = latitude.toDouble()
102-
val lon: Double = longitude.toDouble()
103-
return search(lat,lon,limit,offset)
104-
}
134+
): List<SearchResult>
135+
= search(latitude.toDouble(),longitude.toDouble(),limit,offset)
105136
}

osmunda/src/main/java/moe/sunjiao/osmunda/model/Address.kt

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ import android.database.Cursor
44
import android.database.sqlite.SQLiteDatabase
55
import java.util.*
66

7+
/**
8+
* get full address from a search result
9+
* created on 4/22/2020.
10+
*
11+
* @author Sun Jiao(孙娇)
12+
*
13+
* @param name name of location
14+
* @param databaseId element id in osm data
15+
* @param database database in which this element could be found
16+
* @param latitude latitude of location
17+
* @param longitude longitude of location
18+
* @param locale country or area or language of address
19+
*/
20+
721
class Address(val name: String, databaseId: Long, database: SQLiteDatabase, val latitude: Double, val longitude: Double, private var locale: Locale? = null ) {
822
var state: String = ""
923
var city: String = ""
@@ -99,14 +113,16 @@ class Address(val name: String, databaseId: Long, database: SQLiteDatabase, val
99113
}
100114
if (county == ""){
101115
val where_county_way = sqliteStatement.county_way
102-
val list = arrayListOf<result>()
116+
val list = arrayListOf<Result>()
103117
val cursor: Cursor = database.rawQuery("SELECT * FROM tag inner join nodes, way_no on tag.id=way_no.way_id and way_no.node_id=nodes.id where $where_county_way group by tag.id order by (lat - ?) * (lat - ?) + (lon - ?) * (lon - ?) asc limit 1 ",
104118
arrayOf(lat, lat, lon, lon))
105119
if (cursor.moveToNext())
106-
list.add(result(
107-
cursor.getString(cursor.getColumnIndex("v")),
108-
cursor.getDouble(cursor.getColumnIndex("lat")),
109-
cursor.getDouble(cursor.getColumnIndex("lon"))))
120+
list.add(
121+
Result(
122+
cursor.getString(cursor.getColumnIndex("v")),
123+
cursor.getDouble(cursor.getColumnIndex("lat")),
124+
cursor.getDouble(cursor.getColumnIndex("lon")))
125+
)
110126
cursor.close()
111127
val where_county_node = sqliteStatement.county_node
112128
val cursor2: Cursor = database.rawQuery("SELECT * FROM tag inner join nodes on tag.id=nodes.id where $where_county_node group by tag.id order by (lat - ?) * (lat - ?) + (lon - ?) * (lon - ?) asc limit 1 ",
@@ -116,10 +132,10 @@ class Address(val name: String, databaseId: Long, database: SQLiteDatabase, val
116132
val cursor3: Cursor = database.rawQuery("SELECT * FROM tag where id = $id and k = 'name' ", null)
117133
if (cursor3.moveToNext())
118134
list.add(
119-
result(
135+
Result(
120136
cursor3.getString(cursor3.getColumnIndex("v")),
121137
cursor2.getDouble(cursor2.getColumnIndex("lat")),
122-
cursor2.getDouble(cursor2.getColumnIndex("lon")))
138+
cursor2.getDouble(cursor2.getColumnIndex("lon")))
123139
)
124140
cursor3.close()
125141
}
@@ -159,14 +175,16 @@ class Address(val name: String, databaseId: Long, database: SQLiteDatabase, val
159175
}*/
160176
if (neighbourhood == ""){
161177
val where_neighbourhood_way = sqliteStatement.neighbourhood_way
162-
val list = arrayListOf<result>()
178+
val list = arrayListOf<Result>()
163179
val cursor: Cursor = database.rawQuery("SELECT * FROM tag inner join nodes, way_no on tag.id=way_no.way_id and way_no.node_id=nodes.id where $where_neighbourhood_way group by tag.id order by (lat - ?) * (lat - ?) + (lon - ?) * (lon - ?) asc limit 1 ",
164180
arrayOf(lat, lat, lon, lon))
165181
if (cursor.moveToNext())
166-
list.add(result(
167-
cursor.getString(cursor.getColumnIndex("v")),
168-
cursor.getDouble(cursor.getColumnIndex("lat")),
169-
cursor.getDouble(cursor.getColumnIndex("lon"))))
182+
list.add(
183+
Result(
184+
cursor.getString(cursor.getColumnIndex("v")),
185+
cursor.getDouble(cursor.getColumnIndex("lat")),
186+
cursor.getDouble(cursor.getColumnIndex("lon")))
187+
)
170188
cursor.close()
171189
val where_neighbourhood_node = sqliteStatement.neighbourhood_node
172190
val cursor2: Cursor = database.rawQuery("SELECT * FROM tag inner join nodes on tag.id=nodes.id where $where_neighbourhood_node group by tag.id order by (lat - ?) * (lat - ?) + (lon - ?) * (lon - ?) asc limit 1 ",
@@ -176,7 +194,7 @@ class Address(val name: String, databaseId: Long, database: SQLiteDatabase, val
176194
val cursor3: Cursor = database.rawQuery("SELECT * FROM tag where id = $id and k = 'name' ", null)
177195
if (cursor3.moveToNext())
178196
list.add(
179-
result(
197+
Result(
180198
cursor3.getString(cursor3.getColumnIndex("v")),
181199
cursor2.getDouble(cursor2.getColumnIndex("lat")),
182200
cursor2.getDouble(cursor2.getColumnIndex("lon")))
@@ -205,9 +223,12 @@ class Address(val name: String, databaseId: Long, database: SQLiteDatabase, val
205223
}
206224
}
207225

226+
/**
227+
* @param result query result from Geocoder or ReverseGeocoder
228+
*/
208229
constructor(result: SearchResult) : this(result.name, result.databaseId, result.database, result.lat, result.lon)
209230

210-
class result (val name: String, val lat: Double, val lon: Double)
231+
private class Result (val name: String, val lat: Double, val lon: Double)
211232
}
212233

213234
/*

osmunda/src/main/java/moe/sunjiao/osmunda/model/IfStatement.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ package moe.sunjiao.osmunda.model
22

33
import java.util.*
44

5+
/**
6+
* if statement in different language to fix issue in osm raw data
7+
* created on 4/24/2020.
8+
*
9+
* @author Sun Jiao(孙娇)
10+
*/
11+
512
class IfStatement (){
613

714
var city : (current: String, key: String, value: String) -> Boolean = { _, key, _ -> key == "city" || key.endsWith(":city") }
@@ -15,6 +22,9 @@ class IfStatement (){
1522

1623
init{ }
1724

25+
/**
26+
* @param locale country or area or language of address
27+
*/
1828
constructor(locale: Locale?): this(){
1929
when (locale) {
2030
Locale.SIMPLIFIED_CHINESE, Locale.CHINA, Locale.CHINESE, Locale.PRC -> this(

0 commit comments

Comments
 (0)