Is it possible to retrieve full (structured) addresses for the specific POINT_ADDRESS tile using HERE Map Attributes API v8? - here-api

I'm trying to use HERE Map Attributes API to retrieve the addresses for some map area.
As far as I understood the layer I need is the POINT_ADDRESS layer (check the docs).
The problem is that the layer contains coordinates and identifiers only, but not the structured addresses:
[
{
"ADDRESS_POINT_ID": "334030589",
"LINK_ID": "1286528309",
"SIDE": "R",
"ADDRESSES": "ENGBN682",
"ADDRESS_TYPE": "1",
"BUILDING_NAMES": "ENGBNnull",
"DISPLAY_LAT": "-2751772",
"DISPLAY_LON": "15307500",
"ARRIVAL_LINK_ID": null,
"ARRIVAL_SIDE": null,
"LAT": "-2751797",
"LON": "15307488",
"TOPOLOGY_ID": "215602187",
"START_OFFSET": "8043"
},
...
]
So the question is: how to retrieve the structured address for every point from the POINT_ADDRESS layer? Should I use HERE Batch Geocoder API and perform reverse geocoding for these points? Or it's still possible to achieve that with Map Attributes API only?

On this link https://developer.here.com/documentation/content-map-attributes/dev_guide/topics/here-map-content.html are not all layers in the list.
Please see all layers on https://demo.support.here.com/pde .
In the weu region on https://demo.support.here.com/pde/layers?region=WEU&release=latest&url_root=pde.api.here.com
To retrieve the structured address you need additional layers ROAD_ADMIN_NAMES and ROAD_NAME
Then you request will be like: https://smap.hereapi.com/v8/maps/attributes.json?in=proximity:-27.51772,153.075001;r=100&layers=ROAD_NAME_FCn,ROAD_ADMIN_NAMES_FCn,POINT_ADDRESS&apikey=
Regarding docs on https://developer.here.com/documentation/content-map-attributes/api-reference.html
The parameter 'in' could be: proximity or bbox or corridor - for these in case for big areas you can get limitations due big data. Therefore some times it could be better use in=tile:...
Tile Ids you can get by these formulas:
tile size = 180° / 2^level [degree]
tileY = trunc((latitude + 90°) / tile size)
tileX = trunc((longitude + 180°) / tile size)
tileID = tileY * 2 * (2^level) + tileX
Or you can read this documentation https://demo.support.here.com/pde/indexes?region=WEU&release=latest&url_root=pde.api.here.com
How to get tileid by some index like:
https://smap.hereapi.com/v8/maps/index.json?layer=ROAD_GEOM_FCn&attributes=LINK_ID&values=1286528309,130742823
Then by tile request will be like:
https://smap.hereapi.com/v8/maps/attributes?apikey=&layers=POINT_ADDRESS,ROAD_NAME_FC4,ROAD_NAME_FC5,ROAD_ADMIN_NAMES_FC4,ROAD_ADMIN_NAMES_FC5&in=tile:46594870,11648411,46594870,11648411,46594870

Related

Download traffic flow data and weather data

I am looking to download the traffic flow data and the weather data having the conditions
Particular date
Particular location(zipcode or latitude/longitude or geolocations)
I have seen some examples in this link to collect data using quadkey, bounding box, and corridor. https://developer.here.com/documentation/examples/rest/traffic/traffic-flow-quadkey
My questions are
How could I specify the date or range of dates?
How could I get the quadkey, bounding box, and corridor of location?
I need the data of the previous day, it's not like historical, do I need a subscription for that
Please find the answers inline:
By default, traffic tiles show real-time traffic, representing the traffic situation at the time of the request.
However, it is also possible to request a traffic tile showing the typical traffic pattern for a specific time and day during the week. To get a traffic pattern tile, add a &time parameter to the request, specifying the date and time for which to display the traffic situation. Based on historic information, the tile displays a typical traffic situation for that date and time.
More information provided here:
https://developer.here.com/documentation/map-tile/dev_guide/topics/traffic-tiles.html
The traffic flow is explained based on color code explained here:
https://developer.here.com/documentation/traffic/dev_guide/topics/tiles.html
Green = Free flow of traffic: 0 <= JAM_FACTOR < 4
Yellow = Sluggish flow of traffic: 4 <= JAM_FACTOR < 8
Red = Slow flow of traffic: 8 <= JAM_FACTOR < 10
Black = Traffic stopped flowing or road closed: JAM_FACTOR = 10
(I) a quadkey is a string containing a numeric value. The value is obtained by interleaving the bits of the row and column coordinates of a tile in the grid at the given zoom level, then converting the result to a base-4 number (the leading zeros are retained). The length of a quadkey string (the number of digits/characters) equals the zoom level of the tile.
For example:
// Convert the column (x) and row (y) values
// to their binary (b) equivalents:
x = 3 -> 011b
y = 5 -> 101b
// Interleave the binary values (b), convert the
// combined result to a base-4 (q) number and
// finally convert that to a string:
quadkey = 100111b -> 213q -> "213"
Here is the Javascript example that calculates the quadkey:
--- input ---
xTile: 35210 // Column
yTile: 21493 // Row
z: 16 // Zoom Level
--- JavaScript ---
function tileXYToQuadKey(xTile, yTile, z) {
var quadKey = "";
for (var i = z; i > 0; i--) {
var digit = "0",
mask = 1 << (i - 1);
if ((xTile & mask) != 0) {
digit++;
}
if ((yTile & mask) != 0) {
digit = digit + 2;
}
quadKey += digit;
} // for i return quadKey;
return quadKey;
}
quadKey = tileXYToQuadKey(35210, 21493, 16);
--- output ---
quadKey = "1202102332221212"
(II) The query parameter bbox defines the latitudes and longitudes of the top left and bottom right corners of the bounding box. The optional query parameter response attributes requests that the response include additional information on the shape and the functional class of the roadway corresponding to the flow items.
The bbox can be obtained from the geocode & search API.
For example:
Request:
https://geocode.search.hereapi.com/v1/geocode?q=5+Rue+Daunou%2C+75000+Paris%2C+France
The response will have the map view containing the co-ordinates:
"mapView": {
"west": 2.33073,
"south": 48.86836,
"east": 2.33347,
"north": 48.87016
},
The detail information is explained here: https://developer.here.com/documentation/geocoding-search-api/dev_guide/topics/endpoint-geocode-brief.html
(III) Corridor Entrypoint represents sets of places along a route area sorted by distance from starting point of the route.
This information is available in the old search API
https://developer.here.com/documentation/places/dev_guide/topics_api/resource-browse-by-corridor.html
With the new GS7 API you can refer to this link:
https://developer.here.com/documentation/geocoding-search-api/dev_guide/topics/implementing-route.html
As mentioned in point 1, the traffic map tile is available for a given time by adding the parameter &time parameter to the query.

How to get X Y Z coordinates of tile by click on Leaflet map

I want to ask for help to deal with the possible use of non-standard coordinates on the map Leaflet.
I want to use Leaflet to display custom maps with my own tile generator. Tiles are generated on the fly by script, depending on where it is planned to display (parameters {x}, {y}, {z} in the URL request to the script)
Map will be zoomable (from 0 to 10), size of ~16000 * 16000 tiles in maximum zoom, and 16 * 16 tiles in a minimum) and it will display a variety of objects, each object in a separate tile.
Each tile of 64 * 64 pixels is the object on map.
For each object (a square-tile) I want to display it`s information on mouse click, by sending via AJAX request to the server. I did not want to pre-load all information about all objects for the goal of optimization.
My main issue - I cannot understand how to correctly get the X Y Я coordinates of the tile on which mouse clicked.
Essentially because each tile when it is loaded from the server is bound to the grid {x}, {y}, {z}, and so I want to get these {x}, {y}, {z} from clicks on the map and send them for further AJAX request for getting information about the object.
Now it is possible to get click point as Latlng coordinates or coordinates in pixels relative to the upper-left corner of the map, which I cannot reference to tiles grid.
And also I wanted to know the possibility to get the coordinates of the click relative to the tile. For example, If the tile has dimensions of 64 * 64, and click was in the center of the tile, so how can I get relative coordinate of click [32, 32]?
Because If we knowing {X}, {Y}, {Z} coordinates of the tile and relative X* and Y* coordinates of click inside the tile, then we can do “universal alternative coordinate grid”.
May be this is not a problem and it can be solved easily, but I've never worked with any Maps API, and therefore I want to know the answer to this question.
Thanks in advance for your help!
Here is a working example for getting Zoom, X, and Y coordinates of clicked tile (using openstreet map): http://jsfiddle.net/84P9r/
function getTileURL(lat, lon, zoom) {
let xtile = parseInt(Math.floor((lon + 180) / 360 * (1 << zoom)));
let ytile = parseInt(Math.floor((1 - Math.log(Math.tan(lat.toRad()) + 1 / Math.cos(lat.toRad())) / Math.PI) / 2 * (1 << zoom)));
return zoom + "/" + xtile + "/" + ytile;
}
based on an answer https://stackoverflow.com/a/19197572
You can use the mouseEventToLayerPoint and mouseEventToContainerPoint methods in the Leaflet API to convert pixels onscreen to pixels relative to the top-left of the map, and then using a little math, you can derive the location within a tile.
This is what Leaflet does internally:
const tileSize = [256, 256]
let pixelPoint = map.project(e.latlng, map.getZoom()).floor()
let coords = pixelPoint.unscaleBy(tileSize).floor()
coords.z = map.getZoom() // { x: 212, y: 387, z: 10 }

Check if a point is inside a Polygon with the Google Maps API

I am developing an application using the Google Maps API v3, and I'm struggling to know how to find out if an X coordinate is inside a polygon.
You can use the Geometry Library of the Google Maps JS API. There's a function called containsLocation which tells you if a given LatLng is inside a Polygon. Note that it's a Polygon, not a Polyline. A Polyline is (as it says in the name) a line. So there is no such thing as a point being inside a polyline. You can check if a point is inside a Polygon with the containsLocation function.
google.maps.geometry.poly.containsLocation(somePoint, somePolygon)
In iOS it can be done by using GMSGeometryContainsLocation
Just create a GMSMutablePath, then fill with vertexes of your polygon and test the point.
Example(Swift 4.0):
func isWithin(_ point: CLLocationCoordinate2D) -> Bool {
let p = GMSMutablePath()
p.add(CLLocationCoordinate2D(latitude:30.02356126, longitude: -90.07047824))
p.add(CLLocationCoordinate2D(latitude:30.02501037, longitude: -90.0614231))
p.add(CLLocationCoordinate2D(latitude:30.03321034, longitude: -90.0617981))
p.add(CLLocationCoordinate2D(latitude:30.03192855, longitude: -90.07342815))
return GMSGeometryContainsLocation(point, p, true)
}
Note: If the last param of GMSGeometryContainsLocation is set to true, the GMSMutablePath is composed of great circle segments, otherwise it's of rhumb (loxodromic) segments.

Nokia Places API? Is there a detailed description of search results? And how heavity is this api used?

Has anyone worked with Nokia places API. I am not seeing a lot of activity on the community forum? I was curious about the level of use that it has in the industry? here is my question:
1) What is meaning of having []? What could have been specified here?
2) What is the unit of distance? is it meters? feet?
3) how accurate is vicinity? is this the real address of starbucks or just an approximation?
if approx. how accurate is it?
{ Starbucks } { position: [ 40.74864 , -73.98841 ] distance: 270 title: Starbucks averageRating: 0.0 category: { Coffee/Tea } icon: http://download.vcdn.nokia.com/p/d/places2/icons/categories/23.icon vicinity: 906 6th Ave ↵
New York City NY 10001 ↵
USA having: [ ] type: urn:nlp-types:place href: http://demo.places.nlp.nokia.com/places/v1/places/840dr5ru-846b0ffe4ec64caf83a11bafd4b5a5b9;context=Zmxvdy1pZD04ZWY4YTY4Ni1iN2RhLTVhYTEtOGM0Mi1kNjYxNTM0NGEyNThfMTM2MzAzNjEyNDY1Nl8wXzQ3NTEmcmFuaz0x?app_id=myappid&app_code=myappcode id: 840dr5ru-846b0ffe4ec64caf83a11bafd4b5a5b9 } ,
...Nokia places API. ... the level of use that it has in the industry?
The RESTful places API is used as a back-end service by here.com, so a places request is made to the service whenever a user requires more details about a place. As regards third party usage I haven't got the details. Personally I see using a place service as a good way of easily adding value to an app without much effort - say for example your organization has data about country-side walks - you could easily add value to your app by finding "places to eat and drink" near to your route(s) without needing to become an expert on pubs and restaurants - which would be outside of your domain of expertise.
1) What is meaning of having []? What could have been specified here?
I can't see having [] as being documented in the current release documentation - I believe it is a place holder for further information - if you read the definition of the extensible contract you will see that additional elements may be added to the feed at any time - your best bet here is to ignore the attribute for now.
2) What is the unit of distance? is it meters? feet?
Distances are in metres - you can use a function like the one below to convert
function calculateDistance(distance){
if (metricMeasurements){
if (distance < 1000){
return "" + distance + " m.";
} else {
return "" + Math.floor(distance/100)/10 + " km.";
}
} else {
if (distance < 1610){
return "" + Math.floor(distance/1.0936) + " yards";
} else {
return "" + Math.floor(distance/160.934)/10 + " miles";
}
}
}
3) how accurate is vicinity? is this the real address of starbucks
or just an approximation? if approx. how accurate is it?
Vicinity is described in the documentation here - it can be used to filter out more distant places if necessary. For an individual place the address element holds the full address details, with the address.text holding the formatted address. Regarding the specific place query - here.com has a Starbucks at 906 6th Ave. This can be confirmed by another source here.

SQL query to query nearby points of interest based on lat/long - SQLite

Given a database that contains three fields:
Latitude
Longitude
Proximity
Where Lat and Long are GPS coordinates, and Proximity is (some unit - feet? Seconds? Minutes?)
And given the user's current GPS lat/long...
I want to write a SQL query that will retrieve all rows where the user is within "Proximity" of those rows.
And the trick: This has to work in SQLite, which only supports fairly primitive data types. No cheating and relying on SQL Server (or some other product that provides better geospace functions).
Any suggestions?
Here is a C-based custom function for sqlite [copied from links noted below]. This can be used within an iOS app. It assumes you have columns named latitude and longitude, and calculates the difference between them and any lat/long coordinates you provide. Excellent write-up, works as-is.
#define DEG2RAD(degrees) (degrees * 0.01745327) // degrees * pi over 180
static void distanceFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
{
// check that we have four arguments (lat1, lon1, lat2, lon2)
assert(argc == 4);
// check that all four arguments are non-null
if (sqlite3_value_type(argv[0]) == SQLITE_NULL || sqlite3_value_type(argv[1]) == SQLITE_NULL ||
sqlite3_value_type(argv[2]) == SQLITE_NULL ||
sqlite3_value_type(argv[3]) == SQLITE_NULL) {
sqlite3_result_null(context);
return;
}
// get the four argument values
double lat1 = sqlite3_value_double(argv[0]);
double lon1 = sqlite3_value_double(argv[1]);
double lat2 = sqlite3_value_double(argv[2]);
double lon2 = sqlite3_value_double(argv[3]);
// convert lat1 and lat2 into radians now, to avoid doing it twice below
double lat1rad = DEG2RAD(lat1);
double lat2rad = DEG2RAD(lat2);
// apply the spherical law of cosines to our latitudes and longitudes, and set the result appropriately
// 6378.1 is the approximate radius of the earth in kilometres
sqlite3_result_double(context, acos(sin(lat1rad) * sin(lat2rad) + cos(lat1rad) * cos(lat2rad) * cos(DEG2RAD(lon2) - DEG2RAD(lon1))) *
6378.1);
}
This defines an SQL function distance(Latitude1, Longitude1,
Latitude2, Longitude2), which returns the distance (in kilometres)
between two points.
To use this function, add the code above ... and
then add this line immediately after you call sqlite3_open:
sqlite3_create_function(sqliteDatabasePtr, "distance", 4, SQLITE_UTF8, NULL, &distanceFunc, NULL, NULL);
…where sqliteDatabasePtr is the database pointer returned by your call
to sqlite3_open.
Assuming you have a table called Locations, with columns called
Latitude and Longitude (both of type double) containing values in
degrees, you can then use this function in your SQL like this:
SELECT * FROM Locations ORDER BY distance(Latitude, Longitude, 51.503357, -0.1199)
This example orders the locations in your database based on how far
away they are from the London Eye, which is at 51.503357, -0.1199.
EDIT :
Original link http://www.thismuchiknow.co.uk/?p=71 is dead, so as someone mentioned in comment, you can use this link : https://web.archive.org/web/20160808122817/http://www.thismuchiknow.co.uk/?p=71 to get that webpage
The Haversine formula is what you want. Using simple Euclidian distance formula isn't sufficient, because the curvature of the earth affects the distance between two points.
Creating a Store Locator with PHP, MySQL & Google Maps is an article about implementing this solution with MySQL, but SQLite doesn't support trig functions.
Check out the answers in Calculating Great-Circle Distance with SQLite here on Stack Overflow for further tips on extending SQLite functions so you can solve this.
You also know that there is a plugin for SQLite called Spatialite which has all the same functions as PostGIS and SQLServer? I assume you are trying to use SQLLite on the iPhone or in the browser or something. If not they I HIGHLY reccomend spatialite.

Resources