Approach sounds reasonable. Does geocoder return speed limit in the API response?
Not the default response, but you can call /details with place_id and that will have an extras->maxspeed object if applicable.
I still need to work out the unit to store in, nominatim will return km/h as a number or 'xx mph' if in mph. This will probably be related to the attributes by the look of it.
The approach I am taking is to extend Geocoder with:
String getSpeedLimit(String way, ReverseGeocoderCallback callback);
And extend JsonGeocoder as:
public JsonGeocoder(String url, final int cacheSize, AddressFormat addressFormat, String speedurl) {}
with a fallback for providers that do not support speed limits:
public JsonGeocoder(String url, final int cacheSize, AddressFormat addressFormat) {}
Then the providers are extended with:
private static String formatSpeedUrl(String url, String key, String language) {}
and in parseAddress call:
address.setWay(result.getString("place_id"));
Then after a succesful call
handleSpeedResponse(String way, JsonObject json, ReverseGeocoderCallback callback){}
will format the speed and return it.
Then I need to figure out how to link that to the device attribute... getting there.
printJsonObject(result);
if (json.containsKey("display_name")) {
address.setFormattedAddress(json.getString("display_name"));
}
@@ -81,6 +115,9 @@ public class NominatimGeocoder extends JsonGeocoder {
if (result.containsKey("postcode")) {
address.setPostcode(result.getString("postcode"));
}
if (result.containsKey("place_id")) {
address.setWay(result.getString("place_id"));
}
return address;
}
@Override JsonObject result = json.getJsonObject("address");
if (result != null) {
LOGGER.info("Geocode called.");
Address address = new Address();
printJsonObject(result);
if (json.containsKey("display_name")) {
address.setFormattedAddress(json.getString("display_name"));
}
@@ -81,6 +115,9 @@ public class NominatimGeocoder extends JsonGeocoder {
if (result.containsKey("postcode")) {
address.setPostcode(result.getString("postcode"));
}
if (result.containsKey("place_id")) {
address.setWay(result.getString("place_id"));
}
return address;
}
Pull request submitted:
I've noticed a few requests for per-road speed limits and no implementation has surfaced as of yet, so I am working on this now.
To start with I am only implementing this with Nominatim Geocoder (extends jsonGeocoder).
I am extending Geocoder->Address with a speedLimit property.
Handler->Events->OverspeedEventHandler is being extended to use the following priority:
Address Limit (if available) -> Geofence Limit (if available) -> Global Limit
I welcome any suggestions or feedback before I get too dug in.