Magento发票获取送货地址

I want to show the shipping address of an order on my invoices. This is working pretty well with:

$shipping = nl2br($order->getShippingAddress()->format('html'));
$shipping = explode('<br />',$shipping);

But if I have an order for a download product (gift card) I get a:

Fatal error: Call to a member function format()...

Because the order does not have a shipping address. How can I check, whether $order->getShippingAddress() contains any data or, if not, not displaying it?