GeoLocationService Replacement Call For Getting Lat/Long (PHP Library)

174 views
Skip to first unread message

Paul NMP

unread,
Nov 10, 2015, 3:01:16 PM11/10/15
to AdWords API Forum
Hi,

Our PHP system is retrieving latitude/longitude for location ID's, using the pre-v201509 GeoLocationService and Address class from the PHP Lib


$geoLocationService
= $user->GetService('GeoLocationService', ADWORDS_VERSION);

$address
= new Address();
$address
->countryCode = 2826;   //UK Country Code
$selector
= new GeoLocationSelector();
$selector
->addresses = array($address);

$result
= $geoLocationService->get($selector);

$geoLocation
= $result[0];

if ($geoLocation->GeoLocationType != 'InvalidGeoLocation') {
        $lat
= $geoLocation->geoPoint->latitudeInMicroDegrees / AdWordsConstants::MICRO_DEGREES_PER_DEGREE;
        $long
= $geoLocation->geoPoint->longitudeInMicroDegrees / AdWordsConstants::MICRO_DEGREES_PER_DEGREE;
}


We're updating our code, but the GeoLocationService etc has been removed in v201509

What would the recommended replacement for the above call be? There doesn't seem to be a way to get that info without associating the request with a campaign?

Thanks

Paul

Anthony Madrigal

unread,
Nov 10, 2015, 3:19:29 PM11/10/15
to AdWords API Forum
HI Paul,

In order to retrieve/create a Proximity using AdWords API v201509, you will need to use the CampaignCriterionService. When making the request, you do not need to necessarily associate it with a campaign, however, you will get the Proximities of all campaigns if you don't.

Cheers,
Anthony
AdWords API Team

Orangevn

unread,
Nov 11, 2015, 2:20:55 AM11/11/15
to AdWords API Forum

Hi Anthony,


I have a problem the same Paul.

Previous, I using CampaignCriterionService  for get locations  of a campaign existing. But in case, I need search Radius Targeting  with paramater  is Address.  But, in CampaignCriterionService  Address File is not filterable.

How to search Radius targeting when input address to text search.






Thanks


Vào 03:19:29 UTC+7 Thứ Tư, ngày 11 tháng 11 năm 2015, Anthony Madrigal đã viết:

Paul NMP

unread,
Nov 11, 2015, 1:20:41 PM11/11/15
to AdWords API Forum
Hi Anthony,

I'm still a bit confused...

In my sample v201502 code, I used a GeoLocationSelector. There's no corresponding selector in CampaignCriterionService which can take an address object?

Or am I missing something?

Thanks for your help!

Paul

Anthony Madrigal

unread,
Nov 12, 2015, 9:36:57 AM11/12/15
to AdWords API Forum
Hey guys,

Here is how most users would create a Proximity criteria in versions v201506 and earlier:
  1. Submit a GeoLocationService.get with the GeoLocationSelector.address set to the address around which they wanted to target.
  2. Verify that the response from #1 was not an InvalidGeoLocation object.
  3. Use the returned GeoLocation.geoPoint when creating the Proximity object, as described here: https://developers.google.com/adwords/api/docs/guides/location-targeting#proximity-targeting.
You can skip steps 1 and 2 and just use the Address from step 1 as the Proximity.address in step 3 since the GeoLocationService is now sunset in future versions. So instead of using Proximity.geoPoint, use Proximity.address. You will get a failure if the address is invalid when using the CampaignCriterionService.mutate.

Paul NMP

unread,
Nov 12, 2015, 10:27:19 AM11/12/15
to AdWords API Forum
Thanks Anthony, but that doesn't really answer my question :)

I can create the proximity object...

            $campaignCriterionService = $user->GetService('CampaignCriterionService', ADWORDS_VERSION);

           
//Set the address

            $address
= new Address();
            $address
->countryCode = 2826;   //UK Country Code

           
            $prox
= new Proximity();
            $prox
->address = $address;
            $prox
->radiusDistanceUnits = "KILOMETERS";
            $prox
->radiusInUnits = 0;

...which gets me up step 3. But how do I use that to retrieve the lat/long co-ords of the Proximity object using the recommended CampaignCriterionService?

In the old code, you had a GeoLocationSelector which could be used to retrieve that data. That no longer exists, and none of the selectors in CampaignCriterionService are filterable on proximity.

I want to get the latitude and longitude of country code 2826. What is step 4? :)

Anthony Madrigal

unread,
Nov 12, 2015, 4:31:14 PM11/12/15
to AdWords API Forum
Hi,

Even though Address is not filterable, you can still select it. If you add Address in your selector, you should see data for your geoPoints as well in your SOAP response.

If you are still not seeing it, please send me your SOAP request and response through reply privately to author and I'll be happy to take a look into it.

Regards,
Anthony
AdWords API Team
Reply all
Reply to author
Forward
0 new messages