city( $_SERVER[ 'REMOTE_ADDR' ] ); $result = array( 'data' => array( 'country' => $record->country->name, 'region' => $record->mostSpecificSubdivision->name, 'city' => $record->city->name, 'lat' => $record->location->latitude, 'lng' => $record->location->longitude ) ); } catch ( Exception $e ) { if ( $e->getMessage() !== '' ) { $result = array( 'data' => array( 'country' => 0, 'region' => 0, 'city' => 0, 'lat' => 0, 'lng' => 0 ) ); } } echo json_encode( $result );