Bing maps: Direct Access to tiles and Api key - bing-maps

i am using Bing map tiles in my Android application. I download tiles from http://h0.ortho.tiles.virtualearth.net/tiles/h<quadkey>.jpeg?g=131 and it works fine, but i understand that i need to append a token to this URL in order to make this operation legal (and ask some kind of special permission from Microsoft). It is all well explained here: http://blogs.msdn.com/b/virtualearth/archive/2008/04/29/tracking-virtual-earth-tile-usage.aspx. But this post is from 2008 and i found on msdn site that in 2012, token-auth system will be replaced with key auth system.
Does anybody know how can i perform the direct tile access with this new auth system?
Thanks in advance

Accessing tiles directly with key-based authentication can be accomplished like so:
Using the REST ‘Get Imagery Metadata’ service to obtain the tile URL format for the type of tiles you wish to display:
http://msdn.microsoft.com/en-us/library/ff701716.aspx
- For example, if you wish to display Road tiles, the following request could be used (taken from the above documentation): http://dev.virtualearth.net/REST/V1/Imagery/Metadata/Road?mapVersion=v1&output=xml&key=BingMapsKey
Within the response, the URL for tiles is returned, with a placeholder for the tile quadkey.
A new REST request should be issued each time the map viewer in the application is instantiated, or whenever the map type is changed (eg. You wish to switch to aerial or hybrid map style)
Your platform usage can then be tracked based on the calls to the REST service.

Related

Standard way to display Bing API Truck Route JSON response on a Bing Map?

I'm successfully calling Bing's Truck Route API (below) to get a JSON response for a route.
https://learn.microsoft.com/en-us/bingmaps/rest-services/routes/calculate-a-truck-route
What's the standard way to get that to show up on a Bing Map? From their documentation here, I can't quite tell.
https://learn.microsoft.com/en-us/bingmaps/rest-services/imagery/get-a-static-map
To display a truck route result on an interactive map in Bing Maps, the easiest option is to leverage the directions module which supports truck routing. The directions module is an integrated part of the interactive map SDK. Here are some examples:
https://www.bing.com/api/maps/sdk/mapcontrol/isdk/directionscreatetruckroute
https://learn.microsoft.com/en-us/bingmaps/v8-web-control/map-control-concepts/directions-module-examples/calculate-driving-directions
If you want to instead directly access the REST routing API and display the results from that on a map, you will need to loop through and extract the route points from the route response, and create a line.

Hiding fusion charts license

I have a purchased license at fusion charts. Fusion charts document says here... https://www.fusioncharts.com/dev/upgrading/license-activation that i have to use this function call for applying license...
FusionCharts.options.license({
key: 'KEY_GOES_HERE',
creditLabel: false,
});
if i put my key in that anyone visiting my website can easily take it from view -> source of browser. how do i avoid it ? It is simple HTML website.
You can use either of the followings :
Instead of passing the keys directly in JS code, pass them via the environment, application variables. And add the env file to gitignore
Use Obfuscation for the key and JS code being used for license activation.
You can store the value of the key in your database & and fetch the data value so that the end-user is unable to access it.
If you know the domain/sub-domains where charts will be used, you can restrict the license keys to those domains by sending a request to sales#fusioncharts.com
As far as I know, there is no way to completely hide it from the frontend. The reason for this is that even if the key is hidden in some way when the request is made, the information has to exist and so the key could be found by looking at the request data.
What you wish to protect against determines how you should go about it. If you would just like to hide it from being picked up by webscrapers, then I would imagine encrypting it and then decrypting it before you send would be sufficient.
If you would like to protect against anyone stealing it, then the only way is to have a server act as a proxy. You would make a call to an API which would then use your API key on the backend, away from the prying eyes of users. Your backend API would then just return to the user the response from fusioncharts.

react-leaflet not loading tiles and gilving 403 request error

I am using react-leaflet with tile provider Stadia OSM bright. when I run it locally Is showing tiles but when I make build and upload to server It stops loading tiles and starts giving request 403 forbidden error. I have an API key but not finding any solution where to put it in the component. here is a code sample
render() {
const headeris = {"Authorization": "Stadia-Auth "+this.state.authkey}
return (
<LeafletMaps
center={[this.state.lat, this.state.lng]}
zoom={12}
maxZoom={17}
attributionControl={true}
zoomControl={true}
doubleClickZoom={true}
scrollWheelZoom={true}
dragging={true}
animate={true}
easeLinearity={0.5}
>
<TileLayer
url="https://tiles.stadiamaps.com/tiles/osm_bright/{z}/{x}/{y}{r}.png"
attribution= '© Stadia Maps, © OpenMapTiles © OpenStreetMap contributors'
/>
{this.state.markers.map((position, index) => (
<Marker
key={`marker-${index}`}
position={[position[0][4], position[0][5]]}
>
<Popup>
<p>{position[0][0]}</p>
<a href={`/admin/calender/${position[0][2]}`}>Book now</a>
</Popup>
</Marker>
))}
</LeafletMaps>
);
Section for other people
As mentioned you need to first register to get an API key if not developing locally. From your question I can see that you have done that and are asking where to insert the key once you have it.
Once registered you can
Add your website domain to the Stadia whitelist using the dashboard presented
However if like me you are not using a specific website, or location you may instead append the API key to the URL. NOTE: Rather than the usual ?apikey= syntax Stadia opts for the use of an underscore ?api_key= (this caught me out too!).
This means you need to change your code in the following way to get it to work:
<TileLayer
url="https://tiles.stadiamaps.com/tiles/osm_bright/
{z}/{x}/{y}{r}.png?api_key=your_api_key_goes_here"
<... rest of code ...>
Hopefully, that should solve your problem - good hacking!
general description and alternative solution (for quite complete solution regarding Api insertion see user2589273 answer below),
i've also been tricked at first but all resolved now. As Stadia Maps States in their Api keys page, "You can get started developing locally without any effort or cost. You can get started right away with a web server running on localhost or 127.0.0.1. Once you're ready to deploy, you can sign up for free". please refer to https://docs.stadiamaps.com/#api-keys ,
so you need to signup if you are using it in production, they have a free plan (up to 2500 requests per day for non commericals).
note that you don't need an api key, as they have another solution includes providing your domain name so they can track your traffic.
Stadiamaps also supports adding a domain next to API keys. When you create a property, you have the option to generate an API key or add a domain. When serving your website with javascript opt for the domain. As you generally don't want to expose your keys.

How to embed a public Mapbox style by using user's own access token

FCC provides a style id from their website which is
https://api.mapbox.com/styles/v1/fcc/ck07351k218h31cp7om3z4bka.html?fresh=true&title=true&access_token=pk.eyJ1IjoiZmNjIiwiYSI6ImNqY2h2MnAxbDJhZjIycXBnN3cxb3FnYzAifQ.-JIKXvGZ-ZI2m7L8f92Lew#3.0/37.000000/-95.000000/0
However, when I tried to embed the style into my website, it is not working.
My code is
mapboxgl.accessToken = 'myowntoken';
var map = new mapboxgl.Map({
container: "map",
style: "mapbox://styles/fcc/ck07351k218h31cp7om3z4bka",
center: [-121.064242, 36.922103], // starting position
zoom: 5
});
I wonder why this happened?
It's likely that FCC only allows using this style with their token. The note on their documentation website says:
Note: In order to access these layers, in the various formats below, you need a Mapbox access token. We are including a public access token in the links below since we want to make it easy for people to access broadband data in whatever format is most useful. However, if we find that the access token is being abused, and in particular being used to access maps unrelated to the broadband map, we will have no choice but to deactivate the token, and require end users to get their own token.
While it implies that you could use your own token, it seems like they didn't actually enable this functionality.
You can use the token they provided for the time being.

ESRI ArcGIS REST API URL giving me a blank image

I'm trying to use the following URL to export a map image and I'm not getting anything other than a blank image...
http://demographics6.arcgis.com/arcgis/rest/services/USA_Demographics_and_Boundaries_2016/MapServer/export?f=json&format=png&bbox=-82.728110%2C27.719379%2C-82.532320%2C27.816795&size=600,600&token=[my-token]
Any ideas?
Are you constructing this url yourself or is that request coming from a layer added to the map?
After logging in to ArcGIS Online, I was able to use the export endpoint just fine with this url:
http://demographics6.arcgis.com/arcgis/rest/services/USA_Demographics_and_Boundaries_2016/MapServer/export?bbox=-2.601910765504469E7%2C4619421.289780159%2C1199812.3691861853%2C1.6262309438175105E7&size=600%2C600&format=png&f=json
My hunch is you are supplying an invalid bounding box, it looks like it may be in a different spatial reference than the service, the service is expecting web mercator (102100) and looks like you may be giving it geographic (4326)