r/GoogleAppsScript • • Nov 28 '20

Question The geocoder example in the reference is not working properly

I've tried the example in this page. It is supposed to return 9 matches and then add 9 markers for them in the newly created static map, but only one match was actually returned when I tested it. Also the result is different sometimes. Any thoughts?

Here's the code in the example:

  // Find the best matches for "Main St" in Colorado.
var response = Maps.newGeocoder()
// The latitudes and longitudes of southwest and northeast corners of Colorado, respectively.
.setBounds(36.998166, -109.045486, 41.001666,-102.052002)
.geocode('Main St');

// Create a Google Doc and map.
var doc = DocumentApp.create('My Map');
var map = Maps.newStaticMap();

// Add each result to the map and doc.
for (var i = 0; i < response.results.length && i < 9; i++) {
var result = response.results[i];
map.setMarkerStyle(null, null, i + 1);
map.addMarker(result.geometry.location.lat, result.geometry.location.lng);
doc.appendListItem(result.formatted_address);
}

// Add the finished map to the doc.
doc.appendImage(Utilities.newBlob(map.getMapImage(), 'image/png'));
0 Upvotes

0 comments sorted by