你好!
当 Geolocator().placemarkFromAddress() 的参数地址正确时,它运行良好。
但是,地址不正确(在谷歌地图上找不到),此函数返回“ PlatformException (PlatformException(ERROR_GEOCODNG_ADDRESSNOTFOUND, Unable to find坐标匹配提供的地址。, null)) ”
喜欢这张照片
因此,如果地址不正确,我怎样才能获得空值而不是“PlatformException (PlatformException(ERROR_GEOCODNG_ADDRESSNOTFOUND, Unable to find坐标与提供的地址匹配。空))”的异常?
你好,你解决了吗?
@NaufalHafizi你可以简单地使用 try...catch 语句:
List<Placemark> placemarks = null;
try {
placemarks = await Geolocator().placemarkFromAddress(query);
} on PlatformException catch (e) {
if (e.errorCode == 'ERROR_GEOCODING_ADDRESSNOTFOUND') {
placemarks = null;
} else {
// Don't handle this case so rethrow the exception...
rethrow;
}
}
请注意,作为地理定位器 6.0.0 版的一部分,我们已将地理编码功能移至他们自己的专用插件中,并从地理定位器插件中删除了placemarkFromAddress
和placemarkFromCoordinates
。
@NaufalHafizi你可以简单地使用 try...catch 语句:
List<Placemark> placemarks = null; try { placemarks = await Geolocator().placemarkFromAddress(query); } on PlatformException catch (e) { if (e.errorCode == 'ERROR_GEOCODING_ADDRESSNOTFOUND') { placemarks = null; } else { // Don't handle this case so rethrow the exception... rethrow; } }
请注意,作为地理定位器 6.0.0 版的一部分,我们已将地理编码功能移至他们自己的专用插件中,并从地理定位器插件中删除了
placemarkFromAddress
和placemarkFromCoordinates
。
谢谢你
@NaufalHafizi你可以简单地使用 try...catch 语句:
List<Placemark> placemarks = null; try { placemarks = await Geolocator().placemarkFromAddress(query); } on PlatformException catch (e) { if (e.errorCode == 'ERROR_GEOCODING_ADDRESSNOTFOUND') { placemarks = null; } else { // Don't handle this case so rethrow the exception... rethrow; } }
请注意,作为地理定位器 6.0.0 版的一部分,我们已将地理编码功能移至他们自己的专用插件中,并从地理定位器插件中删除了
placemarkFromAddress
和placemarkFromCoordinates
。谢谢你
if (e.errorCode == 'ERROR_GEOCODING_ADDRESSNOTFOUND')
这里“e.errorcode”对我不起作用
它显示了 getter 'errorcode' 不是为 'PlatformException' 类型定义的
你会帮忙看看吗。