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

Turf.js生成圆形多边形出现经度坐标异常问题求助

Fixing Turf.js Circle Polygon Coordinate Mismatch

Hey there! I see exactly what's going wrong here—this is a super common gotcha with GIS libraries that follow GeoJSON standards.

The Root Cause

Turf.js (and all GeoJSON-compliant tools) expects coordinates in the [longitude, latitude] order, but you've passed your center point as [latitude, longitude] instead.

Let's break it down clearly:

  • Your original center: [20.659698486328125, -103.349609375] → Turf reads this as longitude=20.66, latitude=-103.35 (a spot way south near Antarctica, which explains the weird longitude values in your output)
  • The correct order should be: [-103.349609375, 20.659698486328125] → longitude=-103.35, latitude=20.66 (the central Mexico location you intended)

Corrected Code

Here's the fixed version of your code with the coordinate order swapped:

var center = [-103.349609375, 20.659698486328125]; // [longitude, latitude]
var options = { steps: 5, units: 'kilometers', options: {} };
var radius = 1;
var polygon = turf.circle(center, radius, options);

What to Expect Now

When you run this corrected code, the generated polygon coordinates will be centered around your intended location, with both longitude and latitude values matching the area near -103.35, 20.66.

A quick pro tip: Always double-check coordinate order when working with GeoJSON-based libraries—this mix-up is one of the most frequent issues folks run into when getting started with turf.js or similar tools.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 03:57:10