Magento – Get Shipping Adress City State From Checkout page In Custom Module Magento 2

checkoutmagento2shipping

How to get city state value from onepage checkout in Magento 2 in custom module
i had use below code for Magento 1.X but cant do it for magento 2.x
have any suggestion ? how can i get these values ?

Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getCity();

Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getRegionId();

Best Answer

We can do the same:

/**
 * @var \Magento\Checkout\Model\Session
 */
protected $_checkoutSession;

public function __construct(
    \Magento\Checkout\Model\Session $checkoutSession
)
{
    $this->_checkoutSession = $checkoutSession;

}

And then, we can get:

 $this->_checkoutSession->getQuote()->getShippingAddress()->getCity();
 $this->_checkoutSession->getQuote()->getShippingAddress()->getRegionId();