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

更新AirMapMarker管理的视图的coordinate属性时出错问题求助

Fixing "error while updating property 'coordinate' of a view managed by airmapmarker" in React Native

Hey there, I’ve spotted the exact issue causing this error—let’s break it down and fix it quickly!

What’s Going Wrong?

You’re passing the full origin and destination objects (which contain details, geometry data, etc.) directly to the coordinate prop of your <Marker> components. But the AirMap Marker component expects coordinate to be a plain object with only latitude and longitude properties—it doesn’t know how to parse the full place object you’re sending it.

Luckily, you already created the correct coordinate objects (originLoc and destinationLoc) earlier in your RouteMap component—you just aren’t using them for the markers!

Step-by-Step Fix

  1. Update the Marker components to use the originLoc and destinationLoc variables you already defined, instead of the raw origin/destination objects:
<MapView style={{ width: '100%', height: '100%' }}
  provider={PROVIDER_GOOGLE}
  showsUserLocation={true}
  initialRegion={{
    latitude: 28.450627,
    longitude: -16.263045,
    latitudeDelta: 0.0222,
    longitudeDelta: 0.0121,
  }}>
  <MapViewDirections
    origin={originLoc}
    destination={destinationLoc}
    apikey={GOOGLE_MAPS_APIKEY}
    strokeWidth={5}
    strokeColor="black"
  />
  <!-- Here's the fix -->
  <Marker coordinate={originLoc} title={'Origin'} />
  <Marker coordinate={destinationLoc} title="Destination" />
</MapView>
  1. Add Safety Checks (Optional but Recommended)
    To avoid crashes if your route params are missing or the details/geometry data isn’t loaded correctly, use optional chaining and fallback values when creating your coordinate objects:
const originLoc = {
  latitude: origin?.details?.geometry?.location?.lat || 28.450627, // Fallback to your initial region lat
  longitude: origin?.details?.geometry?.location?.lng || -16.263045, // Fallback to your initial region lng
};
const destinationLoc = {
  latitude: destination?.details?.geometry?.location?.lat || 28.450627,
  longitude: destination?.details?.geometry?.location?.lng || -16.263045,
};

Why This Works

By passing the properly formatted originLoc and destinationLoc (which only have the latitude and longitude values the Marker needs), you’re giving the AirMap component exactly what it expects for the coordinate prop—no more parsing errors!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.27 17:47:27