Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Nominatim-based per-road speed limits. #4255

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Escalion
Copy link

These changes implement the reading of the extratags object in nominatim, which includes maxspeed (Speed limit).
We automatically detect kph or mph and convert to knots, which is checked in the overspeed event.

@Escalion
Copy link
Author

@tananaev I have a private nominatim instance if you require to use this for testing

@@ -40,7 +44,7 @@ public NominatimGeocoder(String url, String key, String language, int cacheSize,
@Override
public Address parseAddress(JsonObject json) {
JsonObject result = json.getJsonObject("address");

JsonObject extrasresult = json.getJsonObject("extratags");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can probably be moved to the place you actually use the variable.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, will be in next commit

}
url += "?format=json&lat=%f&lon=%f&zoom=18&addressdetails=1";
url += "reverse?format=json&lat=%f&lon=%f&zoom=16&addressdetails=1&extratags=1";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we changing zoom?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zoom 18 takes you to features such as gardens and parks, zoom 16 keeps you at street level.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does zoom 16 give you house numbers? That's the reason we are using 18.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but in absence of house numbers and for devices with low accuracy, it will return inaccurate addresses, for example with my test device, was on a road but reported it was in a garden off of the road. Maybe the solution is to add a variable in the config to select this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Configuration sounds good to me.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will explore this at the weekend


public class NominatimGeocoder extends JsonGeocoder {

private static final Logger LOGGER = LoggerFactory.getLogger(NominatimGeocoder.class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is logger used for?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was for debugging, will remove.

@@ -112,6 +145,44 @@ public void failed(Throwable throwable) {
return null;
}

@Override
public double getSpeedLimit(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a second method?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we have a second cache for speeds and I couldn't find a good way to return the speed from the original function without changing the type of the callback (original returns a string), which involves changing all of the files that call it.


void onFailure(Throwable e);

}

String getAddress(double latitude, double longitude, ReverseGeocoderCallback callback);
double getSpeedLimit(double latitude, double longitude, ReverseGeocoderCallback callback);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think getAddress should just return all information.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getAddress returns a string which is accessed by several other files as mentioned in previous comment. I like the idea of attaching speed limit to position. The other way, which is more caching-friendly is to store lat,lon against a place_id and store the speed limit against place_id. This will reduce netowrk calls overall but will require quite a few more changes to implement, plus changes to the way other files call the geocoder.

@@ -143,6 +144,14 @@ public OverspeedEventHandler(Config config, DeviceManager deviceManager, Geofenc
speedLimit = geofenceSpeedLimit;
}

if (Context.getGeocoder() != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we store value in position attributes instead of doing network call twice.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be a good way to handle this - how do we access the position object from the geocoder call however? It only passes latitude and longitude.

Copy link
Member

@tananaev tananaev Mar 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would need to pass more data back from geocoder.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll look into refactoring at the weekend.

@NerdGr8
Copy link

NerdGr8 commented Sep 9, 2022

This is such a great feature, any idea when it could be merged into master?

@Escalion
Copy link
Author

Escalion commented Sep 9, 2022

It would need a lot of work to merge now. I don't have the time to be able to spend on this at the moment unfortunately.

@NerdGr8
Copy link

NerdGr8 commented Sep 9, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants