Get latitude and longitude of a listing

Hi there,

Whith Geolocation enabled, what PHP can I use to read LAT & LON coordinates per listing?

Thanks,

Jovica

Hi,

If you have the listing object (e.g. in the template part or some callback for a HivePress hook):

$latitude=$listing->get_latitude();
$longitude=$listing->get_longitude();

There’s also the WordPress way:

$latitude=floatval(get_post_meta($id, 'hp_latitude', true));
$longitude=floatval(get_post_meta($id, 'hp_longitude', true));

Hope this helps

Thank you Ihor.

How do I access reviews from the $listing?

Kind regards,

Jovica

You can query reviews by listing ID this way:

$reviews = \HivePress\Models\Review::query()->filter(['listing' => 123])->get()->serialize();

The $reviews variable will contain an array of Review objects, these can be used in the same way as Listing objects, for example:

$review->get_rating();