macpan
macpan

Reputation: 93

HERE API GET query for static map marker

I have a tiny application with three files in the same dir:

In main.js:

var platform = new H.service.Platform({
   'apikey': {my API key}

});

var defaultLayers = platform.createDefaultLayers();


var map = new H.Map(
document.getElementById('mapContainer'),
defaultLayers.vector.normal.map,
{
    zoom: 10,
    center: { lng: 17.0, lat: 51.0 }
});

window.addEventListener('resize', () => map.getViewPort().resize());
var behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));
var ui = H.ui.UI.createDefault(map, defaultLayers);
    ui.getControl('zoom').setDisabled(false)

function addWroclove() { 
        var markerWroclaw = new H.map.Marker({ lat: 51.0, lng: 17.0 }, { icon: icon });
        map.addObject(markerWroclaw);
    }
addWroclove();

In python_script.py:

import requests
URL_wro = "https://places.ls.hereapi.com/places/v1/browse?at=17.0%2C51.0&q=Wroclaw&apiKey=MY_API_KEY" 
wro = requests.get(URL_wro)
print(wro.text)

index.html:

<!DOCTYPE html>
<html lang="pl">
<head>
    <title></title>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no"/>
    <meta name="description" content=""/>
    <script src="https://js.api.here.com/v3/3.1/mapsjs-core.js" type="text/javascript" charset="utf-8"></script>
    <script src="https://js.api.here.com/v3/3.1/mapsjs-service.js" type="text/javascript" charset="utf-8"></script>
    <script src="https://js.api.here.com/v3/3.1/mapsjs-ui.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript"  charset="utf-8" src="https://js.api.here.com/v3/3.1/mapsjs-mapevents.js"></script>
    <script type="text/javascript" >window.ENV_VARIABLE = 'https://developer.here.com'</script>
    <script src='https://developer.here.com/javascript/src/iframeheight.js'></script>
    <link rel="stylesheet" type="text/css" href="https://js.api.here.com/v3/3.1/mapsjs-ui.css"/>
</head>
<body>
      <div class="map" id="mapContainer"></div>
</body>
</html>

My question is: when I am trying to send GET query (in python_script.py) I am receiving data but from HERE server and not from map which is on my own remote server. I mean - I want to have a GET's response from map in which i have declared my own marker (markerWroclaw). How to make it works in a proper way?

Upvotes: 1

Views: 149

Answers (1)

Shruti Kuber
Shruti Kuber

Reputation: 397

The browse endpoint will give you places from the HERE server. If you want to call locations that you add on the go, you will need to use the Custom Location API. While you add the location as a marker, you will also have to add it to your custom layer. From there you will be able to call and parse the layer of your custom locations.

As an example, below is the layer of custom POIs that I have uploaded to my map layer.

NAME    WKT
POINT1  POINT(13.402449957770752 52.505308544760155)
POINT2  POINT(13.408663845393365 52.499911895880146)

This can be uploaded using the call below

curl --request -i -X POST
    -H "Content-Type: multipart/form-data"
    -F "zipfile=@my_folder/my_layer_content.zip"
    "https://fleet.ls.hereapi.com/2/layers/upload.json
    ?layer_id=POIS
    &apiKey={YOUR_API_KEY}"

or this web tool.

Once uploaded, you can use this call to retrieve the points in the layer:

https://fleet.ls.hereapi.com/2/search/all.json?apikey={SameAPIKeyUsedToUpload}&layer_id=POIS

You can also perform a bunch of search functions with this layer.

Upvotes: 1

Related Questions