Development component

Hey Guys.

I have created a custom component which gets the longitude and latitude of the user.
Its changed versions several times but this is where I am up to

I have the manifest,json and index.js but siomething is not qute right.
On the screen the custom compoinent has the longitude and latitude but I cannot update the corresponfing users fields.

maifesest,json

{
  "displayName": "where Am I",
  "description": "Fetches the user's current location and updates latitude and longitude in the database.",
  "defaultWidth": 160,
  "defaultHeight": 24,
  "components": "./index.js",
  "category": "Actions",
  "icon": "map-pin",
  "icon": "./example-thumbnail.png",
  "props": [
    {
      "name": "onLocationUpdate",
      "displayName": "Location Update Event",
      "type": "action",
      "arguments": [
        {
          "name": "latitude",
          "displayName": "Latitude",
          "type": "number"
        },
        {
          "name": "longitude",
          "displayName": "Longitude",
          "type": "number"
        }
      ]
    }
  ]
}

index.js

import React, { useEffect } from 'react';
import { Text, View } from 'react-native';

const WhereAmI = ({ onLocationUpdate }) => {
  useEffect(() => {
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(
        (position) => {
          const coords = {
            latitude: position.coords.latitude,
            longitude: position.coords.longitude,
          };

          console.log('Location fetched:', coords);

          // Trigger the onLocationUpdate event with latitude and longitude
          if (onLocationUpdate) {
            onLocationUpdate(coords.latitude, coords.longitude);
          }
        },
        (err) => console.error('Failed to get location:', err.message),
        { enableHighAccuracy: true }
      );
    }
  }, []);

  return (
    <View>
      <Text>Fetching location...</Text>
    </View>
  );
};

export default WhereAmI;

When attempting to populate the users “latitude” & “longitude” values the custom compoent shows me that module but not the 2 elements

any guidance most welcome

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.