How to fetch seamarks with Overpass API? - openstreetmap

I have currently managed to fetch seamarks:type=harbours with XAPI but I found out that XAPI is outdated now and it is better to use Overpass API.
My problem is I have no idea how to convert my search from XAPI to Overpass API.
This is my XAPI search:
http://www.overpass-api.de/api/xapi?node[seamark%3Atype=harbour][bbox=4.04297,51.63984,5.09216,51.87106]
This is the Overpass API request I have tried and it does not work. Nothing is received back. No exceptions are shown:
[out:json][timeout:25];
(
node["seamark:type=harbour"](4.04297,51.63984,5.09216,51.87106);
);
out body;
>;
out skel qt;
Could you help me out with what is my issue here?
Thanks in advance.

Your bounding box is wrong. XAPI uses minlon,minlat,maxlon,maxlat while Overpass API uses minlat,minlon,maxlat,maxlon.
Try this query instead: https://overpass-turbo.eu/s/14R8
[out:json][timeout:25];
(
node["seamark:type=harbour"](4.04297,51.63984,5.09216,51.87106);
);
out body;
>;
out skel qt;

Related

How to get the address from coordinates with Open Street Maps API?

I developed an open-source APP in Cordova (it uses Javascript) and I'm using the Google Maps API, though as the APP is becoming popular my bill is increasing (not nice for a free, ad-free APP). Thus I'd like to move to Open Street Maps.
I've been reading the docs about the Overpass API but I see no simple clear examples of code implementation. I know the sever to use, that I should use HTTP GET requests and use their special XML syntax. But it's not clear how do I pass that XML to the GET request. Furthermore the examples regarding coordinates provides as input a boundary box, not a point (or a point is regarded as a square whose corners are the same?).
<union>
<bbox-query s="51.249" w="7.148" n="51.251" e="7.152"/>
<recurse type="up"/>
</union>
<print mode="meta"/>
Could you kindly provide a simple example in Javascript (for example with $.ajax) on how to get the address of a certain location by providing the geo-coordinates to the API?
Another endpoint, and a short snippet:
fetch("https://nominatim.openstreetmap.org/search.php?q=48.886,2.343&polygon_geojson=1&format=json")
.then(response => response.json())
.then(j => {
console.log(j[0].display_name)
})
After some hours around, I share with you the working solution. Apparently, we should use the Nominatim service from Open Street Maps, and therein the reverse geocoding service. Please read the usage policy to avoid abuses, since this is a completely free service.
const coord = [38.748666, -9.103002]
fetch(`https://nominatim.openstreetmap.org/reverse?lat=${coord[0]}&lon=${coord[1]}&format=json`, {
headers: {
'User-Agent': 'ID of your APP/service/website/etc. v0.1'
}
}).then(res => res.json())
.then(res => {
console.log(res.display_name)
console.log(res.address)
})

Google Maps API returned status 'REQUEST_DENIED' in perl

I am a new one to Perl, While I am trying to write the code to print latitudes and longitude of a location using Geo::Coder::Google it returns "Google Maps API returned status 'REQUEST_DENIED'" error message.
Can anyone help me to fix that issue?
#!/usr/bin/perl
use strict;
use warnings 'all';
use Geo::Coder::Google;
my $geocoder = Geo::Coder::Google->new( apiver => 3 );
my $info = $geocoder->geocode( location => 'Bangalore,Karnataka, India' );
my $location = $info->{geometry}{location};
printf "%s %s\n", $location->{lat}, $location->{lng};
I expect to print latitudes and longitude of Bangalore.
You need to obtain an API key and provide it to the module.
The following is the complete response from Google:
{
status => 'REQUEST_DENIED',
error_message => 'You must use an API key to authenticate each request to Google Maps Platform APIs. For additional information, please refer to http://g.co/dev/maps-no-account',
results => [],
}
(I've obtained this by adding some code to the module.)
The error message reads as follows:
You must use an API key to authenticate each request to Google Maps Platform APIs. For additional information, please refer to http://g.co/dev/maps-no-account
The link from the error message provides instructions on getting an API key if you don't have one, and about properly setting up your account if you do.
The module's documentation specifies how to provide your API key.

Azure Maps Get Map Image Request returns a blank map image

I'm trying to use the Azure Get Map Image API call. When using the "Try It!" feature in the documentation, I get a status 200 (success). When I put the request in the browser, a blank map is returned.
Request:
https://atlas.microsoft.com/map/static/png?subscription-key=<myApiKey>&api-version=1.0&layer=hybrid&zoom=7&center=-122.3927721%2047.568873&height=800&width=800&language=en&style=main
Response:
Please advise. Thank you
I think your request isn't formatted correctly. The center query param needs to have a , between the long and the lat (right now it has a space %20).
Try this:
https://atlas.microsoft.com/map/static/png?subscription-key=<myApiKey>&api-version=1.0&layer=hybrid&zoom=7&center=-122.3927721,47.568873&height=800&width=800&language=en&style=main

golang Chi router with query params not working

I am working on a restful service in golang using chi. I am trying to create a route as below
r.Mount("/api/dest", router.NewDestRouter(chi.NewRouter(), destSrv).InitRoutes())
func (dr *DestRouter) InitRoutes() http.Handler {
dr.router.Post("/{number}/product?version={v}", handlers.HandleProduct(dr.dest))
return dr.router
}
But I try to hit this endpoint via post man I get a 404 not found
http://localhost:8345/api/dest/1235abc/product?version=1
May I know the issue here?
As #mkopriva mentioned, simply use r.URL.Query().Get("version") to get the query parameter.
Met this issue, found status 404, for your situation, only go with /{number}/product, do not need to add the content ?version={v}, chi only match with the path, and then use r.URL.Query().Get("version") to get the query parameters, it will work.

How to get osm_id of the nominatim address component?

This is the example request to nominatim:
http://nominatim.openstreetmap.org/search?q=milan,%20italy&format=json&addressdetails=1&accept-language=en
This is the address:
"address":{"city":"Milan","county":"Milan","state":"Lombardy","country":"Italy","country_code":"it"}
All of address components have osm_id's and I want to know them, like this:
"address":{"city":["Milan", <milanId>],"county":["Milan", <milanId>],"state":["Lombardy", <lombardyId>],"country":["Italy", <italyId>]}
How can I get them?
Depending on your use-case you can use the is_in query of Overpass API. See the example at overpass turbo for the coordinates of Milan:
[out:json][timeout:25];
is_in(45.4667971,9.1904984);
out;