在这里我传递源和目的地的经度和纬度,我得到了响应,但是如何从响应中获得特定的值。我是ios Developer中的新手。我在google API中传递了lat和long
let travelTimeString : NSString = "https://maps.googleapis.com/maps/api/directions/json?origin=19.120912,72.845121&destination=19.110162,72.853951&sensor=false" as NSString
print("travelTimeString",travelTimeString)
let urlStr = travelTimeString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
let searchURL: NSURL = NSURL(string: urlStr! as String)!
do {
let newdata = try Data(contentsOf: searchURL as URL)
if let responseDictionary = try JSONSerialization.jsonObject(with: newdata, options: []) as? NSDictionary {
print("travelTimeString",responseDictionary)
}} catch {
}
i got response like this 那么如何获取持续时间的值(路线->腿部->持续时间)
答案 0 :(得分:0)
您可以使用任何外部库,也可以手动解析,例如:
<UserControl.Resources>
<sys:Double x:Key="BusinessRowHeight">22</sys:Double>
<local:LineMultiplierConverter x:Key="LineXConverter" BaseValue="{StaticResource BusinessRowHeight}" />
</UserControl.Resources>
<ItemsControl Grid.Row="1" ItemsSource="{Binding CarBusiness}" Margin="0 5 0 0">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Line StrokeThickness="1" Stroke="LightGray"
X1="0"
Y1="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource LineXConverter}}"
X2="{Binding RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}, Path=ActualWidth}"
Y2="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource LineXConverter}}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>