我正在使用以下Laravel库,并且有一个问题
我正在尝试使用以下代码获取纬度和经度,但它告诉我“ getLatitude”或“ getLongitude”方法不存在。
$geocode = Geocoder::geocode($direccion)->get();
$geocode->getLatitude();
错误:
消息:“方法照亮\ Support \ Collection :: getLatitude不 存在。”,…}异常:“ BadMethodCallException”文件: “ C:\ xampp \ htdocs \ vuesax \ vendor \ laravel \ framework \ src \ Illuminate \ Support \ Traits \ Macroable.php” 行:104消息:“ Method Illuminate \ Support \ Collection :: getLatitude 不存在。”
与dd($ geocode)
Collection {#496 #items: array:1 [
0 => GoogleAddress {#486
-id: "ChIJFR4I3sXaYpYRzeMjpvVWvSA"
-locationType: "ROOFTOP"
-resultType: array:1 [
0 => "street_address"
]
-formattedAddress: "Piramide 1000, San Miguel, Región Metropolitana, Chile"
-streetAddress: null
-intersection: null
-political: "Chile"
-colloquialArea: null
-ward: null
-neighborhood: null
-premise: null
-subpremise: null
-naturalFeature: null
-airport: null
-park: null
-pointOfInterest: null
-establishment: null
-subLocalityLevels: AdminLevelCollection {#490
-adminLevels: []
}
-partialMatch: false
-coordinates: Coordinates {#499
-latitude: -33.501497
-longitude: -70.651687
}
-bounds: Bounds {#500
-south: -33.502845980291
-west: -70.653035980292
-north: -33.500148019708
-east: -70.650338019708
}
-streetNumber: "1000"
-streetName: "Piramide"
-subLocality: null
-locality: "San Miguel"
-postalCode: null
-adminLevels: AdminLevelCollection {#501
-adminLevels: array:3 [
1 => AdminLevel {#502
-level: 1
-name: "Región Metropolitana"
-code: "Región Metropolitana"
}
2 => AdminLevel {#503
-level: 2
-name: "Santiago"
-code: "Santiago"
}
3 => AdminLevel {#504
-level: 3
-name: "San Miguel"
-code: "San Miguel"
}
]
}
-country: Country {#505
-name: "Chile"
-code: "CL"
}
-timezone: null
-providedBy: "google_maps"
} ] }
我该怎么做?