Team Ai
Apppublic

LiquidAI/LFM2-WebGPU

sourceHugging Faceapache-2.0updated 3mo agoView on Hugging Face
94likes
get_location.js85 linesDownload Raw Back to tools
1/**2 * Get the user's current location using the browser's geolocation API.3 * @returns {Promise<{ latitude: number, longitude: number }>} The current position { latitude, longitude }.4 */5export async function get_location() {6  return new Promise((resolve, reject) => {7    if (!navigator.geolocation) {8      reject("Geolocation not supported.");9      return;10    }11    navigator.geolocation.getCurrentPosition(12      (pos) =>13        resolve({14          latitude: pos.coords.latitude,15          longitude: pos.coords.longitude,16        }),17      (err) => reject(err.message || "Geolocation error"),18    );19  });20}21 22export default (input, output) =>23  React.createElement(24    "div",25    { className: "bg-green-50 border border-green-200 rounded-lg p-4" },26    React.createElement(27      "div",28      { className: "flex items-center mb-2" },29      React.createElement(30        "div",31        {32          className:33            "w-8 h-8 bg-green-100 rounded-full flex items-center justify-center mr-3",34        },35        "📍",36      ),37      React.createElement(38        "h3",39        { className: "text-green-900 font-semibold" },40        "Location",41      ),42    ),43    output?.latitude && output?.longitude44      ? React.createElement(45          "div",46          { className: "space-y-1 text-sm" },47          React.createElement(48            "p",49            { className: "text-green-700" },50            React.createElement(51              "span",52              { className: "font-medium" },53              "Latitude: ",54            ),55            output.latitude.toFixed(6),56          ),57          React.createElement(58            "p",59            { className: "text-green-700" },60            React.createElement(61              "span",62              { className: "font-medium" },63              "Longitude: ",64            ),65            output.longitude.toFixed(6),66          ),67          React.createElement(68            "a",69            {70              href: `https://maps.google.com?q=${output.latitude},${output.longitude}`,71              target: "_blank",72              rel: "noopener noreferrer",73              className:74                "inline-block mt-2 text-green-600 hover:text-green-800 underline text-xs",75            },76            "View on Google Maps",77          ),78        )79      : React.createElement(80          "p",81          { className: "text-green-700 text-sm" },82          JSON.stringify(output),83        ),84  );85