QT Location OSM API Key required
-
I am trying to build a QML Map with the OSM plugin . All the map tiles show Api Key required
How do i set the API key in my QML code ? -
Hi,
Can you share a minimal buildable example that shows that behaviour ?
-
my example
import QtQuick 2.8 import QtLocation 5.9 import QtPositioning 5.9 import QtQuick.Controls 2.1 Item { id: mapItem anchors.fill: parent Rectangle{ anchors.fill: parent Plugin { id: mapPlugin name: "osm" } Map { id: map height : 480 width : 800 plugin: mapPlugin zoomLevel: 16 activeMapType: map.supportedMapTypes[1] copyrightsVisible : false gesture.enabled: false tilt: 0 color: "black" center: marker.coordinate // Draw a small red circle for current Vehicle Location MapQuickItem { id: marker anchorPoint.x: 10 anchorPoint.y: 10 width: 15 coordinate: QtPositioning.coordinate(-25.8,28.1) sourceItem: Rectangle { id: image width:20 height: width radius: width*0.5 color: "red" } } } } }
-
MikeSheldon 24 minutes ago
Hi,
I realise this topic is a bit old but I've just run into this same issue myself, and have discovered a solution for it. So for the sake of anyone else coming across this on Google the mechanism I discovered for providing an API key to the OSM plugin is to set up your own providers repository, that way you can specify the API key as part of the URL template.
I made a simple github repo with a script for creating a repository here: https://github.com/Elleo/qt-osm-map-providers
And I wrote up a more detailed explanation of everything on my blog here: https://blog.mikeasoft.com/2020/06/22/qt-qml-maps-using-the-osm-plugin-with-api-keys/
Hope that helps,
Mike -
@MikeSheldon hi
import QtQuick 2.15
import QtQuick.Window 2.15
import QtLocation 5.15
import QtPositioning 5.15Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")Map{ id: mapView anchors.fill: parent plugin: Plugin{ id:mapPlugin name: "osm" PluginParameter { name: "osm.mapping.providersrepository.address"; value: "http://www.mywebsite.com/osm_repository" } PluginParameter { name: "osm.mapping.highdpi_tiles"; value: true } } activeMapType: supportedMapTypes[1] // Cycle map provided by Thunderforest }
}
this is my qml code i have an api key where can I give in this code -
@Madhusmita_123 said in QT Location OSM API Key required:
i have an api key where can I give in this code
You currently cannot, unfortunately. There is a feature request for it: https://bugreports.qt.io/browse/QTBUG-115742
The feature request describes how to patch qgeotiledmappingmanagerengineosm.cpp to accept an API key (the source code is at https://github.com/qt/qtlocation/blob/dev/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp )