Flutter语言 - 从json中获取LatLong


factory FieldModel.fromJson(String fieldId, Map<dynamic, dynamic> json) =>
FieldModel(
fieldId: fieldId,
ownerId: json['ownerId'],
name: json['name'],
imageUrl: json['imageUrl'],
///how to extract this, its a LatLng class from "google_maps_flutter_platform_interface/src/types/location.dart"
latLng: json['latLng'],
description: json['description'],
charges: json['charges'],
timeSlots: json['timeSlots'],
availability: json['availability'],
);

错误:type '_InternalLinkedHashMap<String,>'不是LatLng的子类型。">

假设json是这样的

... 
"latLng": {"lat": 1234.121, "lng": 958.1232}
...

你必须使用你的latLng值来创建一个latLng对象,

latLng: LatLng(json['latLng']['lat'], json['latLng']['lng']),

最新更新