Remove pushpin on Bing Maps API using Python requests

64 Views Asked by At
imagerySet = "Aerial"
address = session['address']
zoomLevel = ZOOM

url = f"https://dev.virtualearth.net/REST/v1/Imagery/Map/{imagerySet}/{address}/{zoomLevel}"

params = {
    'mapSize': "512,512",
    'format': "png",
    'mapMetadata': "false",
    'key': os.environ.get('BING_MAPS_API'),
    'zoomLevel': zoomLevel,
    'dcl': "1",
}

response = requests.get(url, params=params)
image = open_image(response)

using the dcl param, I can control "decluttering" the pins. But I need the pin gone because I'm using this for a real time computer vision application, and the pin is confusing the model.

Is there a parameter I can pass to get rid of the pushpin using this format?

Thanks!

2

There are 2 best solutions below

0
Duncan Lawler On

You're not using the correct API for getting a map without a pin - the one you have above is specifically to get a map with a pin for a searched location. The API you want is this one: https://dev.virtualearth.net/REST/v1/Imagery/Map/imagerySet?mapArea={mapArea}&mapSize={mapSize} See documentation here: https://learn.microsoft.com/en-us/bingmaps/rest-services/imagery/get-a-static-map If all you have is an address as input, you can turn that into a lat/long with the geocoding service. https://learn.microsoft.com/en-us/bingmaps/rest-services/locations/ By the way, you may want to check the terms of use to make sure what you're doing is allowed. Building a derivative product or training ML applications is not normally part of the imagery license.

0
rbrundritt On

The pin is being added because you specified an address. There are two ways to achieve what you are looking for:

  1. Geocode the address first, then use the coordinates or bounding box to retrieve an image (center or mapArea parameters).
  2. For machine learning purposes, you may find using map tiles directly a more efficient method. This is how many map companies have been doing their AI (e.g. Bing Building extracts). For example: https://shuggiefisher.github.io/machine-learning-with-openstreetmap-tiles.md/