不推荐使用addressDictionary:首先在iOS 11.0中弃用 - 使用@properties

时间:2017-12-27 06:34:49

标签: ios objective-c google-maps core-location

我正在努力获取地点和地址。为了让我的位置成功,但在获取地址时我会收到警告,

       include "init.php";

       $get=$_GET["action"];

       $sql = mysqli_query($conn, "SELECT * FROM $get ORDER BY id DESC LIMIT 6");

       $productCount = mysqli_num_rows($sql); // count the output amount

       if ($productCount > 0) 
       {

       while($row = mysqli_fetch_array($sql)){

       $id = $row["id"];

       $jjode = $row["code"];

       $product_name = $row["network"];

       $details = $row["details"];

       $logo = $row["logo"];

       $price = $row["price"];

       }

对此有任何解决方案......

enter image description here

2 个答案:

答案 0 :(得分:5)

在Swift中

if (error) == nil {
    var placemark = placemarks[0] as? CLPlacemark
    var address = "\(placemark?.thoroughfare ?? ""), \(placemark?.locality ?? ""), \(placemark?.subLocality ?? ""), \(placemark?.administrativeArea ?? ""), \(placemark?.postalCode ?? ""), \(placemark?.country ?? "")"
        print("\(address)")
}

目标C

if (!(error))
    {
        CLPlacemark *placemark = [placemarks objectAtIndex:0];    
        NSString *address = [NSString stringWithFormat:@"%@, %@, %@, %@, %@, %@",
                             placemark.thoroughfare,
                             placemark.locality,
                             placemark.subLocality, 
                             placemark.administrativeArea, 
                             placemark.postalCode,
                             placemark.country];
        NSLog(@"%@", address);

    }

答案 1 :(得分:5)

以迅速的方式回答:“

let street = placemark.thoroughfare! // addressDictionary!["Street"] as? String ?? " "
    let city =  placemark.subAdministrativeArea! // addressDictionary!["City"] as? String ?? " "
    let state = placemark.administrativeArea!//addressDictionary!["State"] as? String ?? " "
    let zip =  placemark.isoCountryCode!// addressDictionary!["ZIP"] as? String ?? " "
    let country = placemark.country! // addressDictionary!["Country"] as? String ?? " "