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

开源项目cfanalytics:如何从Mapbox抓取CrossFit健身房经纬度?

Getting Latitude & Longitude for CrossFit Affiliates via Mapbox

Absolutely! You can pull latitude and longitude coordinates for those CrossFit affiliates using Mapbox's geocoding API—here's a straightforward, developer-friendly approach tailored for your open-source project:

  • Grab a Mapbox API Key first
    Sign up for a free Mapbox account (their free tier includes 100,000 geocoding requests per month, which should cover your initial project needs). Once registered, you’ll get an access token to authenticate your API calls.

  • Use Mapbox's Forward Geocoding API
    This API converts physical addresses into geographic coordinates—perfect for pairing with the address data you’re already fetching from CrossFit’s affiliate info endpoint. You’ll send a request with the full, concatenated address of each gym, and Mapbox will return precise coordinates.

    Here’s an example curl command you can adapt (replace placeholders with your actual data):

    curl "https://api.mapbox.com/geocoding/v5/mapbox.places/123%20Main%20St%2C%20Austin%2C%20TX%2078701%2C%20USA.json?access_token=YOUR_MAPBOX_TOKEN"
    

    Remember to URL-encode the address string (spaces become %20, commas become %2C, etc.) to avoid request errors.

  • Extract Coordinates from the Response
    In the JSON response, locate the center field inside the top matching result. Note that Mapbox returns coordinates in [longitude, latitude] order—don’t mix them up! Here’s a snippet of what this looks like:

    "center": [-97.7431, 30.2672]

  • Pro Tips for Smooth Implementation

    • Boost accuracy: Always use the full address set from CrossFit’s endpoint (address, city, state, postal code, country) when building your geocoding request. More specific data ensures Mapbox returns a precise match.
    • Cache results: Since this is an open-source project, cache coordinates once you fetch them. This saves API request limits and makes your tool faster for repeat users.
    • Follow Mapbox’s terms: Don’t forget to include proper attribution for Mapbox (their rules require this when using their geocoding data) and stay within rate limits to avoid request blocks.

As a bonus hack: Check the CrossFit map page’s underlying code—if it uses Mapbox under the hood, there might already be latitude/longitude values stored in JavaScript variables or DOM elements. Scraping those directly could let you skip API calls entirely! But if that’s not feasible, the Mapbox API is a rock-solid fallback.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 08:49:51