阅读PHP中的Firestore Geopoint对象

我无法读取从Firestore文档的Geopoint获取的对象。

我没有找到任何文档来了解如何使用PHP框架读取此地理位置(尽可能迅速)。

整个数组如下所示:

print_r($barDetails);
Array 
( 
[icone_img] => xqSUmb8kCWIanQj3okaf 
[geopoint] => Google\Cloud\Core\GeoPoint Object 
( 
[latitude:Google\Cloud\Core\GeoPoint:private] => 43.697092 [longitude:Google\Cloud\Core\GeoPoint:private] => 7.274421 
) 
[header_img] => SGYXf7DIYRvvpqLIEZr4 
[nom] => La Lupita 
[styles_ids] => Array 
( 
[0] => fKMTFTgAvhHN9D5e7n3p 
) 
[adresse] => 9 Rue de la Préfecture,06300 nice 
[description] => Aenean dictum lectus est,non fringilla enim tempus et. Nam dapibus elit in lobortis sagittis. Sed quis metus in lacus congue tempus at quis mi. 
)

如果我这样做:

print_r($barDetails['geopoint']);

我得到了这个对象,我无法阅读该对象,以便分别获取经度和纬度:

Google\Cloud\Core\GeoPoint Object 
( 
[latitude:Google\Cloud\Core\GeoPoint:private] => 43.697092
[longitude:Google\Cloud\Core\GeoPoint:private] => 7.274421 
)
a123zxxc 回答:阅读PHP中的Firestore Geopoint对象

  

要访问对象属性,您必须使用->

echo $object->property;


在这种情况下,您要访问geopoint对象的纬度和经度属性。

  

纬度:

echo $barDetails['geopoint']->latitude;

  

经度:

echo $barDetails['geopoint']->longitude;


  

重要。请记住,私有属性只能由定义该属性的类访问。因此,只有将您的媒体资源设置为公开,以上内容才有效。否则,您将需要在类中创建一个方法以允许访问您的私有对象属性。

更多信息可以在其他 Stackoverflow thread中找到。


更新

  

对于私有类成员,您需要在类内部使用一个“ getter”方法或函数,该方法或函数返回纬度和经度的值,以允许访问类外的那些值。

     

纬度:

echo $barDetails['geopoint']->latitude();
  

经度:

echo $barDetails['geopoint']->longitude();

希望这会有所帮助。

,

好的,我看错了方向。 Google\Cloud\Core\GeoPoint具有名为latitude()longitude()的简单功能,可以在here中找到。

/**
     * Get the latitude
     *
     * Example:
     * ```
     * $latitude = $point->latitude();
     * ```
     *
     * @return float|null
     */
    public function latitude()
    {
        $this->checkContext('latitude',func_get_args());
        return $this->latitude;
    }

    /**
     * Get the longitude
     *
     * Example:
     * ```
     * $longitude = $point->longitude();
     * ```
     *
     * @return float|null
     */
    public function longitude()
    {
        $this->checkContext('longitude',func_get_args());
        return $this->longitude;
    }

所以barDetails['geopoint']->latitude();做到了。

本文链接:https://www.f2er.com/3128129.html

大家都在问