从坐标获取阿拉伯语的地址行

时间:2019-01-21 05:52:31

标签: dart flutter

我正在使用Geocoder插件来获取地址行,国家/地区,邮政编码等。

  final coordinates = new Coordinates(26.328446, 50.153868);
  var addresses = await Geocoder.local.findAddressesFromCoordinates(coordinates);
  var first = addresses.first;
  print(addresses);
  print("${first.featureName} : ${first.addressLine}");

返回:

  

颤振:Zarqa Al Yamamah街:Zarqa Al Yamamah街-沙特阿拉伯达兰市Al Dana Al Jenobiah,34453

我想得到相同的结果,但使用阿拉伯语..是否可以通过此插件实现此目的?还是有其他插件可以用阿拉伯语为我返回地址?

2 个答案:

答案 0 :(得分:0)

您可以获取语言代码arar-SA。因此,您需要这样做:

Locale loc = new Locale("ar");
Geocoder geocoder = new Geocoder(this, loc);

或这种方式

geocoder = new Geocoder(this, Locale.ar_SA))

您的代码可以是这样

           Locale loc = new Locale("ar"); 
Geocoder geocoder = new Geocoder(this, loc)) 
final coordinates = new Coordinates(26.328446, 50.153868); 
var addresses = await Geocoder.local.findAddressesFromCoordinates(coordinates); 
var first = addresses.first; 
print(addresses); 
print("${first.featureName} : ${first.addressLine}");

这样做:

Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(this, Locale.ar_SA)) 



addresses = geocoder.getFromLocation(latitude, longitude, 1); // Here 1 represent max location result to returned, by documents it recommended 1 to 5

String address = addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
String city = addresses.get(0).getLocality();
String state = addresses.get(0).getAdminArea();
String country = addresses.get(0).getCountryName();
String postalCode = addresses.get(0).getPostalCode();
String knownName = addresses.get(0).getFeatureName(); // Only if available else return NULL

请参见以下示例:

import 'package:locales/locales.dart';
import 'package:locales/currency_codes.dart';
import 'package:intl/intl.dart';

void main() {
  final locale = Locale.ar_SA;
  final currencyCode = CurrencyCode.sar;
  final format = NumberFormat.simpleCurrency(
      locale: '$locale', name: '$currencyCode', decimalDigits: 2);
  print(locale);                  
  print(currencyCode);            
  print(format.format(123.456));  
}

https://github.com/jifalops/locales

答案 1 :(得分:0)

如果要使用特定的本地语言,则必须使用 apiKey

尝试在您的代码中将Geocoder.local方法替换为Geocoder.google

喜欢这个:

Coordinates coordinates = Coordinates(latLng.lat, latLng.lng);

List<Address> addresses =await Geocoder.google(apiKey,language:'ar').findAddressesFromCoordinates(coordinates);

如何获取 apiKey ?显示Get an API Key