如何访问 geocoder-php/GeocoderLaravel 返回的受保护对象?
How do I access the protected object returned by geocoder-php/GeocoderLaravel?
我安装了geocoder-php/GeocoderLaravel包,并根据文档进行了配置。然后我在控制器函数中 运行 进行了一些测试,它转到 Google,解析了地址并成功返回了地理编码对象,但它受到保护,我无法访问它。这是怎么回事?
代码:
$geocode = Geocoder::geocode('9900 Sowder Village Square, Manassas, VA 20109');
var_dump($geocode);
输出:
object(Geocoder\Result\Geocoded)#189 (15) {
["latitude":protected]=> float(38.7392838)
["longitude":protected]=> float(-77.5348982)
["bounds":protected]=> array(4) {
["south"]=> float(38.7392838)
["west"]=> float(-77.5348982)
["north"]=> float(38.7392838)
["east"]=> float(-77.5348982)
}
["streetNumber":protected]=> string(4) "9900"
["streetName":protected]=> string(21) "Sowder Village Square"
["cityDistrict":protected]=> NULL
["city":protected]=> string(8) "Manassas"
["zipcode":protected]=> string(5) "20109"
["county":protected]=> string(21) "Prince William County"
["countyCode":protected]=> string(21) "PRINCE WILLIAM COUNTY"
["region":protected]=> string(8) "Virginia"
["regionCode":protected]=> string(2) "VA"
["country":protected]=> string(13) "United States"
["countryCode":protected]=> string(2) "US"
["timezone":protected]=> NULL
}
我已经在互联网上搜索并找到了有关反射的内容,但我认为它不会那么复杂。这家伙关于 gitHub 的文档糟透了。有指导吗?
感谢您抽出宝贵时间。
乔希
属性 受到保护,因为 API 不希望您直接触摸属性;他们想使用 getter 和 setter。
http://geocoder-php.org/Geocoder/
getCoordinates()
will return a Coordinates object (with latitude and longitude properties);
这就是你想要的。
我安装了geocoder-php/GeocoderLaravel包,并根据文档进行了配置。然后我在控制器函数中 运行 进行了一些测试,它转到 Google,解析了地址并成功返回了地理编码对象,但它受到保护,我无法访问它。这是怎么回事?
代码:
$geocode = Geocoder::geocode('9900 Sowder Village Square, Manassas, VA 20109');
var_dump($geocode);
输出:
object(Geocoder\Result\Geocoded)#189 (15) {
["latitude":protected]=> float(38.7392838)
["longitude":protected]=> float(-77.5348982)
["bounds":protected]=> array(4) {
["south"]=> float(38.7392838)
["west"]=> float(-77.5348982)
["north"]=> float(38.7392838)
["east"]=> float(-77.5348982)
}
["streetNumber":protected]=> string(4) "9900"
["streetName":protected]=> string(21) "Sowder Village Square"
["cityDistrict":protected]=> NULL
["city":protected]=> string(8) "Manassas"
["zipcode":protected]=> string(5) "20109"
["county":protected]=> string(21) "Prince William County"
["countyCode":protected]=> string(21) "PRINCE WILLIAM COUNTY"
["region":protected]=> string(8) "Virginia"
["regionCode":protected]=> string(2) "VA"
["country":protected]=> string(13) "United States"
["countryCode":protected]=> string(2) "US"
["timezone":protected]=> NULL
}
我已经在互联网上搜索并找到了有关反射的内容,但我认为它不会那么复杂。这家伙关于 gitHub 的文档糟透了。有指导吗?
感谢您抽出宝贵时间。
乔希
属性 受到保护,因为 API 不希望您直接触摸属性;他们想使用 getter 和 setter。
http://geocoder-php.org/Geocoder/
getCoordinates()
will return a Coordinates object (with latitude and longitude properties);
这就是你想要的。