Class PhoneNumberOfflineGeocoder


  • public class PhoneNumberOfflineGeocoder
    extends java.lang.Object
    An offline geocoder which provides geographical information related to a phone number.
    Author:
    Shaopeng Jia
    • Method Detail

      • getDescriptionForValidNumber

        public java.lang.String getDescriptionForValidNumber​(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber number,
                                                             java.util.Locale languageCode)
        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.

        Parameters:
        number - a valid phone number for which we want to get a text description
        languageCode - the language code for which the description should be written
        Returns:
        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

        public java.lang.String getDescriptionForValidNumber​(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber number,
                                                             java.util.Locale languageCode,
                                                             java.lang.String userRegion)
        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.

        Parameters:
        number - the phone number for which we want to get a text description
        languageCode - the language code for which the description should be written
        userRegion - the 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:
        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
      • getDescriptionForNumber

        public java.lang.String getDescriptionForNumber​(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber number,
                                                        java.util.Locale languageCode)
        As per getDescriptionForValidNumber(PhoneNumber, Locale) but explicitly checks the validity of the number passed in.
        Parameters:
        number - the phone number for which we want to get a text description
        languageCode - the language code for which the description should be written
        Returns:
        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

        public java.lang.String getDescriptionForNumber​(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber number,
                                                        java.util.Locale languageCode,
                                                        java.lang.String userRegion)
        As per getDescriptionForValidNumber(PhoneNumber, Locale, String) but explicitly checks the validity of the number passed in.
        Parameters:
        number - the phone number for which we want to get a text description
        languageCode - the language code for which the description should be written
        userRegion - the 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:
        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