Adding latitudes & longitudes programmatically

29 views
Skip to first unread message

cos...@gmail.com

unread,
Oct 30, 2018, 7:24:56 AM10/30/18
to AdWords API and Google Ads API Forum
I'm trying to add some lat/lon with python, my code looks like this:

lx = [{"loc":0, "lat":0}]
operations
= []

for loc in lx:
    criterion
= {
                 
"xsi_type":"Proximity",
                 
"geoPoint":{
"latitude_in_micro_degrees":float(loc['lat']),
"longitude_in_micro_degrees":float(loc['lat'])},
"radius_distance_units":"KILOMETERS", "radius_in_units":50
}

    operations
.append({'operator': 'ADD', 'operand': { 'campaignId': ad_id, 'criterion': criterion} })


operations
= operations[:500] # Google Ads Limit
result
= campaign_criterion_service.mutate(operations)

However I get the error: `KeyError: 'geoPoint'` What am I doing wrong?

Sreelakshmi Sasidharan (AdWords API Team)

unread,
Oct 30, 2018, 1:38:06 PM10/30/18
to AdWords API and Google Ads API Forum
Hello, 

To add a latitude and longitude to proximity criterion, you would need to set the latitude and longitude in micro degrees. Also, the radiusDistanceUnits and radiusInUnits should be set in the proximity object. Could you please give the below code snippet a  try and let me know if that works? 

  proximity = {
      'xsi_type': 'Proximity',
      'geoPoint':{
                  'latitudeInMicroDegrees' : '40712800',
                  'longitudeInMicroDegrees' : '74006000' 
                 },
      'radiusDistanceUnits': 'KILOMETERS',
      'radiusInUnits' : '50.0'

  }

Thanks,
Sreelakshmi, AdWords API Team

cos...@gmail.com

unread,
Nov 1, 2018, 1:50:07 PM11/1/18
to AdWords API and Google Ads API Forum
This worked. Thank you Sreelakshmi!
Reply all
Reply to author
Forward
0 new messages