File: PhoneNumberOfflineGeocoder.md

package info (click to toggle)
php-giggsey-libphonenumber 9.0.23-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,492 kB
  • sloc: php: 485,443; sh: 107; makefile: 37
file content (52 lines) | stat: -rw-r--r-- 1,888 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# PhoneNumberOfflineGeocoder

## Getting Started

As with [PhoneNumberUtil](PhoneNumberUtil.md), the Phone Number Geocoder uses a singleton.

```php
$geoCoder = \libphonenumber\geocoding\PhoneNumberOfflineGeocoder::getInstance();
```

## `getDescriptionForNumber()`

Returns a text description for the supplied `PhoneNumber` object, in the `$locale` language supplied.

The description returned might consist of the name of the country, or the name of the geographical area the phone number is from.

If `$userRegion` is supplied, it will also be taken into consideration. If the phone number is from the same region, only a lower-level description will be returned.

```php
$gbNumber = \libphonenumber\PhoneNumberUtil::getInstance()->parse('0161 496 0123', 'GB');

var_dump($geoCoder->getDescriptionForNumber($gbNumber, 'en'));
// string(10) "Manchester"

var_dump($geoCoder->getDescriptionForNumber($gbNumber, 'en_GB', 'GB'));
// string(10) "Manchester"

var_dump($geoCoder->getDescriptionForNumber($gbNumber, 'en_GB', 'US'));
// string(14) "United Kingdom"

var_dump($geoCoder->getDescriptionForNumber($gbNumber, 'ko-KR', 'US'));
// string(6) "영국" (Korean for United Kingdom)


$usNumber = \libphonenumber\PhoneNumberUtil::getInstance()->parse("+1 650 253 0000", "US");

var_dump($geoCoder->getDescriptionForNumber($usNumber, 'en'));
// string(10) "Mountain View, CA"

var_dump($geoCoder->getDescriptionForNumber($usNumber, 'en_GB', 'GB'));
// string(10) "United States"

var_dump($geoCoder->getDescriptionForNumber($usNumber, 'en_GB', 'US'));
// string(14) "Mountain View, CA"

var_dump($geoCoder->getDescriptionForNumber($usNumber, 'ko-KR', 'US'));
// string(6) "미국" (Korean for United States)
```

## `getDescriptionForValidNumber()`

Returns the same as `getDescriptionForNumber()`, but assumes that you have already checked whether the number is suitable for geolocation.