Class PhoneNumberOfflineGeocoder
- Namespace
- PhoneNumbers
- Assembly
- PhoneNumbers.dll
An offline geocoder which provides geographical information related to a phone number.
public sealed class PhoneNumberOfflineGeocoder
- Inheritance
-
PhoneNumberOfflineGeocoder
- Inherited Members
Remarks
Author: Shaopeng Jia.
Loads phone-prefix → location-string mappings from per-(language, country-code) binary
files generated at build time by <code>PhoneNumbers.MetadataBuilder</code>, via
<xref href="PhoneNumbers.PrefixFileReader" data-throw-if-not-resolved="false"></xref>.
Methods
GetDescriptionForNumber(PhoneNumber, Locale)
As per GetDescriptionForValidNumber(PhoneNumber, Locale) but explicitly checks the validity of the number passed in.
public string GetDescriptionForNumber(PhoneNumber number, Locale languageCode)
Parameters
numberPhoneNumberthe phone number for which we want to get a text description
languageCodeLocalethe language code for which the description should be written
Returns
- string
a text description for the given language code for the given phone number, or empty string if the number passed in is invalid or could belong to multiple countries
GetDescriptionForNumber(PhoneNumber, Locale, string)
As per GetDescriptionForValidNumber(PhoneNumber, Locale, string) but explicitly checks the validity of the number passed in.
public string GetDescriptionForNumber(PhoneNumber number, Locale languageCode, string userRegion)
Parameters
numberPhoneNumberthe phone number for which we want to get a text description
languageCodeLocalethe language code for which the description should be written
userRegionstringthe region code for a given user. This region will be omitted from the description if the phone number comes from this region. It should be a two-letter upper-case CLDR region code.
Returns
- string
a text description for the given language code for the given phone number, or empty string if the number passed in is invalid or could belong to multiple countries
GetDescriptionForValidNumber(PhoneNumber, Locale)
Returns a text description for the given phone number, in the language provided. The description might consist of the name of the country where the phone number is from, or the name of the geographical area the phone number is from if more detailed information is available.
This method assumes the validity of the number passed in has already been checked, and that the number is suitable for geocoding. We consider fixed-line and mobile numbers possible candidates for geocoding.
public string GetDescriptionForValidNumber(PhoneNumber number, Locale languageCode)
Parameters
numberPhoneNumbera valid phone number for which we want to get a text description
languageCodeLocalethe language code for which the description should be written
Returns
- string
a text description for the given language code for the given phone number, or an empty string if the number could come from multiple countries, or the country code is in fact invalid
GetDescriptionForValidNumber(PhoneNumber, Locale, string)
As per GetDescriptionForValidNumber(PhoneNumber, Locale) but also considers the region of the user. If the phone number is from the same region as the user, only a lower-level description will be returned, if one exists. Otherwise, the phone number's region will be returned, with optionally some more detailed information.
For example, for a user from the region "US" (United States), we would show "Mountain View, CA" for a particular number, omitting the United States from the description. For a user from the United Kingdom (region "GB"), for the same number we may show "Mountain View, CA, United States" or even just "United States".
This method assumes the validity of the number passed in has already been checked.
public string GetDescriptionForValidNumber(PhoneNumber number, Locale languageCode, string userRegion)
Parameters
numberPhoneNumberthe phone number for which we want to get a text description
languageCodeLocalethe language code for which the description should be written
userRegionstringthe region code for a given user. This region will be omitted from the description if the phone number comes from this region. It should be a two-letter upper-case CLDR region code.
Returns
- string
a text description for the given language code for the given phone number, or an empty string if the number could come from multiple countries, or the country code is in fact invalid
GetInstance()
Gets a PhoneNumberOfflineGeocoder instance to carry out international phone number geocoding.
The PhoneNumberOfflineGeocoder is implemented as a singleton. Therefore, calling this method multiple times will only result in one instance being created.
public static PhoneNumberOfflineGeocoder GetInstance()
Returns
LoadDataFile(Locale, int)
Preload the data file for the given language and country calling code, so that a future lookup for this language and country calling code will not incur any file loading.
public void LoadDataFile(Locale locale, int countryCallingCode)