Making WordPress.org


Ignore:
Timestamp:
03/03/2017 09:20:07 PM (10 years ago)
Author:
iandunn
Message:

Events API: Normalize coordinates to account for minor differences in databases

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/events/1.0/tests/test-index.php

    r5064 r5065  
    6666                }
    6767
     68                /*
     69                 * Normalize coordinates to account for minor differences in the databases
     70                 *
     71                 * Rounding to three decimal places means that we're still accurate within about 110 meters, which is
     72                 * good enough for our purposes.
     73                 *
     74                 * See https://gis.stackexchange.com/a/8674/49125
     75                 */
     76                if ( isset( $actual_result['latitude'], $actual_result['longitude'] ) ) {
     77                        $actual_result['latitude']  = number_format( round( $actual_result['latitude'],  3 ), 3 );
     78                        $actual_result['longitude'] = number_format( round( $actual_result['longitude'], 3 ), 3 );
     79                }
     80
    6881                $passed      = $case['expected'] === $actual_result;
    6982
     
    121134                        'expected' => array(
    122135                                'description' => 'nairobi',
    123                                 'latitude'    => '-1.2833300',
    124                                 'longitude'   => '36.8166700',
     136                                'latitude'    => '-1.283',
     137                                'longitude'   => '36.817',
    125138                                'country'     => 'KE',
    126139                        ),
     
    135148                        'expected' => array(
    136149                                'description' => 'tokyo',
    137                                 'latitude'    => '35.6895000',
    138                                 'longitude'   => '139.6917100',
     150                                'latitude'    => '35.690',
     151                                'longitude'   => '139.692',
    139152                                'country'     => 'JP',
    140153                        ),
     
    149162                        'expected' => array(
    150163                                'description' => 'berlin',
    151                                 'latitude'    => '52.5243700',
    152                                 'longitude'   => '13.4105300',
     164                                'latitude'    => '52.524',
     165                                'longitude'   => '13.411',
    153166                                'country'     => 'DE',
    154167                        ),
     
    163176                        'expected' => array(
    164177                                'description' => 'vancouver',
    165                                 'latitude'    => '49.2496600',
    166                                 'longitude'   => '-123.1193400',
     178                                'latitude'    => '49.250',
     179                                'longitude'   => '-123.119',
    167180                                'country'     => 'CA',
    168181                        ),
     
    177190                        'expected' => array(
    178191                                'description' => 'brisbane',
    179                                 'latitude'    => '-27.4679400',
    180                                 'longitude'   => '153.0280900',
     192                                'latitude'    => '-27.468',
     193                                'longitude'   => '153.028',
    181194                                'country'     => 'AU',
    182195                        ),
     
    191204                        'expected' => array(
    192205                                'description' => 'são paulo',
    193                                 'latitude'    => '-23.5475000',
    194                                 'longitude'   => '-46.6361100',
     206                                'latitude'    => '-23.548',
     207                                'longitude'   => '-46.636',
    195208                                'country'     => 'BR',
    196209                        ),
     
    205218                        'expected' => array(
    206219                                'description' => 'harare',
    207                                 'latitude'    => '-17.82935',
    208                                 'longitude'   => '31.05389',
     220                                'latitude'    => '-17.829',
     221                                'longitude'   => '31.054',
    209222                                'country'     => 'ZW',
    210223                        ),
     
    215228                        'expected' => array(
    216229                                'description' => 'amman',
    217                                 'latitude'    => '31.95522',
    218                                 'longitude'   => '35.94503',
     230                                'latitude'    => '31.955',
     231                                'longitude'   => '35.945',
    219232                                'country'     => 'JO',
    220233                        ),
     
    225238                        'expected' => array(
    226239                                'description' => 'belfast',
    227                                 'latitude'    => '54.58333',
    228                                 'longitude'   => '-5.93333',
     240                                'latitude'    => '54.583',
     241                                'longitude'   => '-5.933',
    229242                                'country'     => 'GB',
    230243                        ),
     
    235248                        'expected' => array(
    236249                                'description' => 'mexico city',
    237                                 'latitude'    => '19.42847',
    238                                 'longitude'   => '-99.12766',
     250                                'latitude'    => '19.428',
     251                                'longitude'   => '-99.128',
    239252                                'country'     => 'MX',
    240253                        ),
     
    245258                        'expected' => array(
    246259                                'description' => 'auckland',
    247                                 'latitude'    => '-36.86667',
    248                                 'longitude'   => '174.76667',
     260                                'latitude'    => '-36.867',
     261                                'longitude'   => '174.767',
    249262                                'country'     => 'NZ',
    250263                        ),
     
    255268                        'expected' => array(
    256269                                'description' => 'lima',
    257                                 'latitude'    => '-12.043333',
    258                                 'longitude'   => '-77.028333',
     270                                'latitude'    => '-12.043',
     271                                'longitude'   => '-77.028',
    259272                                'country'     => 'PE',
    260273                        ),
Note: See TracChangeset for help on using the changeset viewer.