How to Get Current ZipCode Name in Expo?

Dec 24, 2022 . Admin

Today, I would like to show you how to get current zipcode name in expo. This tutorial will give you simple example of get current zipcode name in expo. We will use how to get current location in expo. you'll learn how to get current component name in expo. You just need to some step to done expo get current zipcode name example.

In this example, we will get to current zipcode name in can use google api key and googple api use then get current zipcode in expo.below this example.

Step 1: Download Project

In the first step run the following command to create a project.

expo init ExampleApp
Step 2: Download Library

In this step run the following command to create a project.

expo install expo-location
Step 3: App.js

In this step, You will open the App.js file and put the code.

import { StyleSheet, Text } from 'react-native'
import React from 'react'
import * as Location from 'expo-location';
let apiKey = 'Your Api Key';

const App = () => {
  const [zipcode, setZipcode] = React.useState('');

  React.useEffect(() => {
    (async () => {

      let { status } = await Location.requestForegroundPermissionsAsync();
      if (status !== 'granted') {
        setErrorMsg('Permission to access location was denied');


      let { coords } = await Location.getCurrentPositionAsync();



      if (coords) {
        let { longitude, latitude } = coords;
        getAddressFromCoordinates(latitude, longitude);
  }, []);

  const getAddressFromCoordinates = async (latitude, longitude) => {
    let findResult = function (results, name) {
      let result = results.find(results, function (obj) {
        return obj.types[0] == name && obj.types[1] == "political";
      return result ? result.short_name : null;
    try {
      const response = await fetch(`${latitude},${longitude}&key=${apiKey}`);
      const json = await response.json();
      const address_components = json.results[0].address_components;

      var state = "";

      for (var i = 0; i < address_components.length; i++) {

        if (address_components[i].types[0] === "postal_code" && zipcode == "") {
          zipcode = address_components[i].long_name;

    } catch (error) {

  return (
    <View style={{
      flex: 1,
      <Text style={{ fontWeight:'bold' }}>Get Current ZipCode Name</Text>
      <Text style={{ backgroundColor:'green', color:'white',padding:10 }}>{zipcode}</Text>

export default App
Step 4: Run Project

In the last step run your project using the below command.

expo start

You can QR code scan in Expo Go Application on mobile.


It will help you...

#React Native