/// <summary> /// Gets the geo location for a given address. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="address">The address for which geolocation should be /// fetched.</param> /// <returns>Geo location for the address.</returns> public GeoLocation GetLocationForAddress(AdWordsUser user, Address address) { GeoLocationService geoService = (GeoLocationService) user.GetService(AdWordsService.v201409.GeoLocationService); GeoLocationSelector selector = new GeoLocationSelector(); selector.addresses = new Address[] {address}; return geoService.get(selector)[0]; }
/// <summary> /// Formats the address as a printable text. /// </summary> /// <param name="address">The address object.</param> /// <returns>The formatted text.</returns> private static string FormatAddress(Address address) { if (address == null) { return "Not available."; } StringBuilder addressBuilder = new StringBuilder(); addressBuilder.AppendFormat("Line 1: {0}\n", address.streetAddress ?? ""); addressBuilder.AppendFormat("Line 2: {0}\n", address.streetAddress2 ?? ""); addressBuilder.AppendFormat("Province Name: {0}\n", address.provinceName ?? ""); addressBuilder.AppendFormat("Province Code: {0}\n", address.provinceCode ?? ""); addressBuilder.AppendFormat("City name: {0}\n", address.cityName ?? ""); addressBuilder.AppendFormat("Postal code: {0}\n", address.postalCode ?? ""); addressBuilder.AppendFormat("Country name: {0}\n", address.countryCode ?? ""); return addressBuilder.ToString(); }