Description Usage Arguments Details Value Note Author(s) References See Also Examples
Does the actual work of finding locations within a given distance of a lat/lon
1 | getPlaces(lat, lon, distance, locLimit)
|
lat |
A latitude |
lon |
A longitude |
distance |
A distance in miles |
locLimit |
A limit on the number of locations |
Note that this function is not meant to be called by the user
A list of locations
None
Steve Pittard
STATS 290 Website
None
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 | ## The function is currently defined as
function (lat, lon, distance, locLimit)
{
library(RCurl)
library(RMySQL)
library(XML)
print("Querying the local Geonames database to see whats nearby")
con = dbConnect(MySQL(), user = "wpittard", password = "t41tt",
dbname = "wpittard")
str1 = "SELECT geo_latitude, geo_longitude, geo_name, "
str2 = paste("(3959*acos(cos(radians(", lat, ")) * cos(radians(geo_latitude)) * cos(radians(geo_longitude) - radians(",
lon, "))", sep = "")
str3 = paste("+ sin(radians(", lat, ")) * sin( radians( geo_latitude)))) AS distance FROM allcountries where ((geo_feature_code like '%ADM%')",
sep = "")
str4 = paste("or (geo_feature_code like '%PPL%') ) having distance < ",
distance, ";", sep = "")
str5 = paste(str1, str2, str3, str4)
rs = dbSendQuery(con, statement = str5)
data = fetch(rs, n = -1)
dbDisconnect(con)
if (nrow(data) >= locLimit) {
newdata = data[sample(nrow(data), size = locLimit), ]
}
else {
newdata = data
}
return(newdata)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.