Get a Random Location

How do I use the API to get a random place on earth that actually has image data. I tried just generating random coordinates but that is horribly inefficient. Getting a list of images gets 200 in the same order.
I’m new and dumb at this and can’t find answers anywhere else.

1 Like

You can use the API to first find recent sequence, then get one random pic from that.

# Mapillary Sequenz von gestern abfragen
y = datetime.today() - timedelta(days=1)
yesterday=y.isoformat()[:10]
client_id = "d0FV..."
link = 'https://a.mapillary.com/v3/sequences?bbox=6,44,16,54&start_time={yesterday}&client_id={client_id}'
link = link.format(yesterday=yesterday,client_id=client_id)
data = requests.get(link).text
data = json.loads(data)
anzahl=len(data['features'])
print ("Anzahl:",anzahl)

# Koordinaten dazu holen
lon=data['features'][anzahl//2]['geometry']['coordinates'][0][0]
lat=data['features'][anzahl//2]['geometry']['coordinates'][0][1]
print ("Position:",lat,lon)

# Bild mit Key holen
key=data['features'][anzahl//2]['properties']['coordinateProperties']['image_keys'][0]
url="https://images.mapillary.com/{key}/thumb-2048.jpg"
url=url.format(key=key)
print ("Bild:",url)

# Download Bild
r = requests.get(url)
with open(mytempfile, 'wb') as f:
    f.write(r.content)
print(r.status_code)
print(r.headers['content-type'])
print(r.encoding)
1 Like

Tried to translate german and python and got this javascript:

let url = "";
let place;
let date = new Date();
date.setDate(date.getDate() - 1);
url = `https://a.mapillary.com/v3/sequences?bbox=6,44,16,54&start_time=${date.toISOString()}&client_id=${clientId}`;
console.log(url);

let keyRequest = new XMLHttpRequest();
keyRequest.open('GET', url, true);

keyRequest.onload = function() {
// Begin accessing JSON data here
let data = JSON.parse(this.response);
place = data.features[data.features.length / 2];
console.log(place);

var mly = new Mapillary.Viewer({
    apiClient: clientId,
    container: 'mly',
    imageKey: place.properties.key,
});
}

keyRequest.send();

its awful and is always the same null image. (using MapillaryJS)

I got everything working but it is always the same image. Not at all random

here is the url I use: https://a.mapillary.com/v3/images?bbox=-85,-180,85,180&start_time=${yesterday.toISOString()}&end_time=${today.toISOString()}&min_quality_score=4&private=false&per_page=1&client_id=${clientId};

Getting a random location could be a good feature for the API.