我尝试使用地理编码器从地址中提取纬度和经度。不幸的是,当我运行下面的代码时,我在所有位置都获得了很长的信息列表。以下是我用于打印展示位置的代码。
geocoder.geocodeAddressString(address, completionHandler: {(placemarks: [AnyObject]!, error: NSError!) -> Void in
if let placemark = placemarks?[0] as? CLPlacemark {
println(placemark)
}
})
我想要的只是lat和long所以我可以保存它。输出结果为:
Infinite Loop<GEOMapItemStorage: 0x7fe4aaf3e4f0> {
placeData = {
component = (
{
"cache_control" = CACHEABLE;
"start_index" = 0;
status = "STATUS_SUCCESS";
timestampFirstSeen = "454307424.248136";
ttl = 2592000;
type = "COMPONENT_TYPE_HOURS";
"values_available" = 0;
version = 1;
"version_domain" = (
apple,
fwdgeo,
US
);
},
{
"cache_control" = CACHEABLE;
"start_index" = 0;
status = "STATUS_SUCCESS";
timestampFirstSeen = "454307424.248136";
ttl = 2592000;
type = "COMPONENT_TYPE_RATING";
"values_available" = 0;
version = 1;
"version_domain" = (
apple,
fwdgeo,
US
);
},
{
"cache_control" = CACHEABLE;
"start_index" = 0;
status = "STATUS_SUCCESS";
timestampFirstSeen = "454307424.248136";
ttl = 2592000;
type = "COMPONENT_TYPE_FLYOVER";
"values_available" = 0;
version = 1;
"version_domain" = (
apple,
fwdgeo,
US
);
},
{
"cache_control" = CACHEABLE;
"start_index" = 0;
status = "STATUS_SUCCESS";
timestampFirstSeen = "454307424.248136";
ttl = 2592000;
type = "COMPONENT_TYPE_BOUNDS";
value = (
{
bounds = {
"map_region" = {
eastLng = "-122.029843";
northLat = "37.3321671";
southLat = "37.3312164";
westLng = "-122.0306393";
};
};
}
);
"values_available" = 1;
version = 1;
"version_domain" = (
apple,
fwdgeo,
US
);
},
{
"cache_control" = CACHEABLE;
"start_index" = 0;
status = "STATUS_SUCCESS";
timestampFirstSeen = "454307424.248136";
ttl = 2592000;
type = "COMPONENT_TYPE_ROAD_ACCESS_INFO";
value = (
{
"access_info" = {
"road_access_point" = (
{
drivingDirection = "ENTRY_EXIT";
location = {
lat = "37.331697";
lng = "-122.0306393";
};
},
{
isApproximate = 1;
location = {
lat = "37.331716";
lng = "-122.030757";
};
walkingDirection = "ENTRY_EXIT";
}
);
};
}
);
"values_available" = 1;
version = 1;
"version_domain" = (
apple,
fwdgeo,
US
);
},
{
"cache_control" = CACHEABLE;
"start_index" = 0;
status = "STATUS_SUCCESS";
timestampFirstSeen = "454307424.248136";
ttl = 2592000;
type = "COMPONENT_TYPE_PLACE_INFO";
value = (
{
"place_info" = {
center = {
lat = "37.3316851";
lng = "-122.0300674";
};
timezone = {
identifier = "America/Los_Angeles";
};
};
}
);
"values_available" = 1;
version = 1;
"version_domain" = (
apple,
fwdgeo,
US
);
},
{
"cache_control" = CACHEABLE;
"start_index" = 0;
status = "STATUS_SUCCESS";
timestampFirstSeen = "454307424.248136";
ttl = 2592000;
type = "COMPONENT_TYPE_ENTITY";
value = (
{
entity = {
"is_disputed" = 0;
name = (
{
locale = "en_US";
"string_value" = "1 Infinite Loop";
}
);
type = ADDRESS;
};
}
);
"values_available" = 1;
version = 1;
"version_domain" = (
apple,
fwdgeo,
US
);
},
{
"cache_control" = CACHEABLE;
"start_index" = 0;
status = "STATUS_SUCCESS";
timestampFirstSeen = "454307424.248136";
ttl = 2592000;
type = "COMPONENT_TYPE_ADDRESS";
value = (
{
address = {
"known_accuracy" = POINT;
"localized_address" = (
{
address = {
formattedAddressLine = (
"1 Infinite Loop",
"Cupertino, CA 95014-2083",
"United States"
);
structuredAddress = {
administrativeArea = California;
administrativeAreaCode = CA;
areaOfInterest = (
"Apple Inc."
);
country = "United States";
countryCode = US;
dependentLocality = (
"Bay Area"
);
fullThoroughfare = "1 Infinite Loop";
geoId = (
);
locality = Cupertino;
postCode = 95014;
postCodeExtension = 2083;
postCodeFull = "95014-2083";
subAdministrativeArea = "Santa Clara";
subLocality = "Bay Area";
subThoroughfare = 1;
thoroughfare = "Infinite Loop";
};
};
locale = "en_US";
}
);
};
}
);
"values_available" = 1;
version = 1;
"version_domain" = (
apple,
fwdgeo,
US
);
},
{
"cache_control" = CACHEABLE;
"start_index" = 0;
status = "STATUS_SUCCESS";
timestampFirstSeen = "454307424.248136";
ttl = 2592000;
type = "COMPONENT_TYPE_AMENITIES";
"values_available" = 0;
version = 1;
"version_domain" = (
apple,
fwdgeo,
US
);
},
{
"cache_control" = CACHEABLE;
"start_index" = 0;
status = "STATUS_SUCCESS";
timestampFirstSeen = "454307424.248136";
ttl = 2592000;
type = "COMPONENT_TYPE_STYLE_ATTRIBUTES";
"values_available" = 0;
version = 1;
"version_domain" = (
apple,
fwdgeo,
US
);
},
{
"cache_control" = CACHEABLE;
"start_index" = 0;
status = "STATUS_SUCCESS";
timestampFirstSeen = "454307424.248136";
ttl = 2592000;
type = "COMPONENT_TYPE_BUSINESS_CLAIM";
"values_available" = 0;
version = 1;
"version_domain" = (
apple,
fwdgeo,
US
);
}
);
"result_provider_id" = 6489;
status = "STATUS_SUCCESS";
};
}
答案 0 :(得分:2)
您正在使用println获取数据的文本转储。 CLPlaceMark是一种数据结构。
将此代码添加到您的闭包代码中,您已完成设置:
latitude = placemark.location.coordinate.latitude;
longitude = placemark.location.coordinate.longitude;
检查排序顺序。您可能希望选择第一个和最后一个元素,并确定是否通过增加或减少置信度排序来对其进行排序。 placemark [placemark.count -1]将为您提供最后一个元素。