You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何生成包含Geofire密钥的模拟数据?

Solution for Generating Mock Data with GeoFire Keys

Hey there! I’ve run into a similar snag with Mockaroo before—turns out it doesn’t have a built-in feature to generate GeoFire keys directly. But don’t stress, there are two solid workarounds to get the mock data your feature depends on:

1. Generate Lat/Lon First, Then Convert to GeoFire Keys

This is the most straightforward approach if you don’t mind a quick post-processing step:

  • In Mockaroo, create two number fields:
    • latitude: Set the range to -90 to 90 (valid global latitude values)
    • longitude: Set the range to -180 to 180 (valid global longitude values)
  • Export your mock dataset (CSV, JSON, etc.) once it’s generated
  • Use GeoFire’s official SDK to convert each pair of coordinates into a GeoFire key. Here’s a quick JavaScript example:
const GeoFire = require('geofire');

// Example entry from your Mockaroo data
const mockLocation = { latitude: 37.7749, longitude: -122.4194 };
const geofireKey = GeoFire.encodeGeohash(mockLocation.latitude, mockLocation.longitude);

console.log(geofireKey); // Outputs the corresponding GeoHash key

2. Use Mockaroo’s Custom Script Field to Generate Keys Directly

If you want to skip post-processing entirely, you can embed a GeoHash encoding script directly into Mockaroo:

  • Add a new field to your Mockaroo schema, set its type to Script
  • Paste a complete GeoHash encoding function into the script editor (you can find open-source GeoHash implementations online that work in vanilla JS)
  • Modify the script to generate random valid coordinates, then encode them into a GeoFire key. Here’s a simplified template:
// Full GeoHash encoding function (replace with a complete public implementation)
function encodeGeohash(latitude, longitude) {
  const base32Chars = '0123456789bcdefghjkmnpqrstuvwxyz';
  // Insert full GeoHash encoding logic here (plenty of free implementations exist online)
}

// Generate random valid coordinates
const randomLat = Math.random() * 180 - 90;
const randomLon = Math.random() * 360 - 180;

// Return the encoded GeoFire key
return encodeGeohash(randomLat, randomLon);

Once you save this script, Mockaroo will generate a valid GeoFire key for each entry in your dataset automatically.

Either method should get you the mock data you need to test your feature that relies on GeoFire keys.

内容的提问来源于stack exchange,提问作者about14sheep

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:35:18