City Lookup

Platform: API iOS Android

City Lookup provides reverse geocoding, geolocation lookup services, supports multi-language, fuzzy search and other functions.

With the City Lookup, you can get the basic information of the city, including the Location ID of the city (you need this ID to get the weather), multilingual name, latitude and longitude, time zone, altitude, rank, administrative, etc.

In addition, GeoAPI - City Lookup can also help you to implement fuzzy search in your APP, users only need to type 1 or 2 words to get results.

Interface code Interface Class
geoCityLookup City lookup GeoCityLookupResponse

Parameters

GeoCityLookupParameter

  • location(required)The location to be queried, support text, LocationID, comma-separated longitude and latitude (decimal, up to 2 decimal places), Adcode(Chinese cities only). For example: location=beijing or location=116.41,39.92
  • admSuperior administrative divisions of a city, useful for excluding cities with similar names or for filtering results. Example adm = beijing
  • rangeSet to search only within a certain country or region. The country and region name needs to use country code ISO 3166. If this parameter is not set, the search range will be all cities. Example: range=cn
  • numberNumber of the results in response, from 1 to 20, 10 is the default.
  • langMulti-language setting, please see Language to find out how our multi-language works and how to set up.

Sample code

Swift

Task{
    do {
        let response =  try await QWeather.instance
            .geoCityLookup(.init(location: "101010100"))
        print(response)
    } catch QWeatherError.errorResponse(let error) {
        print(error)
    } catch {
        print(error)
    }
}

Objective-C

GeoCityLookupParameter *parameter = [GeoCityLookupParameter instanceWithLocation:@"116.41,39.92"
                                        adm:nil
                                    range:@(RangeCN)
                                    number:@(10)
                                    lang:@(LangZH_HANS)];
[QWeatherObjc geoCityLookup: parameter completionHandler:^(GeoCityLookupResponse * _Nullable response, NSError * _Nullable error) {
    if (response) {
        NSLog(@"%@", response.description);
    }
    if (error) {
        NSLog(@"%@", error.localizedDescription);
    }
}];

Response

GeoCityLookupResponse

  • code See Status Code
  • location.name Location Name
  • location.id Location ID
  • location.lat Latitude of the location
  • location.lon Longitude of the location
  • location.adm2 Name of the superior administrative division of the location
  • location.adm1 The first-level administrative area of ​​the location
  • location.country Country name of the location
  • location.tz Location timezone
  • location.utcOffset The number of hours offset between local time and UTC time, refer to UTC Offset
  • location.isDst Is the location currently on daylight saving time. 1 for daylight saving time and 0 for not in daylight saving time
  • location.type Location type
  • location.rank Location Rank
  • location.fxLink Responsive web page of this location, easy to embed in your website or APP
  • refer.sources Data source and other statements, may be null
  • refer.license Data license, may be null