Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google maps 使用Google Directions API显示地点名称_Google Maps_Flutter - Fatal编程技术网

Google maps 使用Google Directions API显示地点名称

Google maps 使用Google Directions API显示地点名称,google-maps,flutter,Google Maps,Flutter,我正在尝试向Google Directions API发出一个包含多个航路点的请求。到目前为止一切正常,但我遇到的主要问题是,当谷歌地图应用程序为用户打开时,用户只能看到坐标 Future<void> launchGoogleMaps(BuildContext context) async { Position userLocation = await Geolocator().getLastKnownPosition( desiredAccuracy: L

我正在尝试向Google Directions API发出一个包含多个航路点的请求。到目前为止一切正常,但我遇到的主要问题是,当谷歌地图应用程序为用户打开时,用户只能看到坐标


  Future<void> launchGoogleMaps(BuildContext context) async {
    Position userLocation = await Geolocator().getLastKnownPosition(
      desiredAccuracy: LocationAccuracy.bestForNavigation,
    );

    String googleMapsAppUrl = 'comgooglemapsurl://?';

    if (customFirstPlace != null) {
      googleMapsAppUrl +=
          "saddr=${customFirstPlace.latitude},${customFirstPlace.longitude}";
    } else if (!shouldStartWithUserLocation) {
      googleMapsAppUrl +=
          "saddr=${circuitCompanies[0].lat},${circuitCompanies[0].lng}";
    }

    String googleMapsWebUrl = "http://www.google.com/maps/dir";
    googleMapsWebUrl += "/${userLocation.latitude},${userLocation.longitude}";

    circuitCompanies.forEach((CompanyModel element) {
      int elementIndex = circuitCompanies.indexOf(element);
      // If it's the first element, the "direction"
      // parameter will be added to specify the beginning.
      // If not, the "to" parameter will be added
      // to specify a waypoint (a stop).

      if (elementIndex == 0) {
        googleMapsAppUrl += "&daddr=${element.lat},${element.lng}";
      } else {
        googleMapsAppUrl += "+to:${element.lat},${element.lng}";
      }

      googleMapsWebUrl += "/${element.lat},${element.lng}";
    });

    if (await canLaunch("comgooglemaps://")) {
      print('launching com googleUrl $googleMapsAppUrl');
      await launch(googleMapsAppUrl);
    } else if (await canLaunch(googleMapsWebUrl)) {
      print('launching web url $googleMapsWebUrl');
      await launch(googleMapsWebUrl);
    } else {
      showDialog(
        builder: (_) {
          return SingleActionDialog(
            title: "Erreur",
            onConfirmTap: () => Navigator.pop(context),
            bodyText: "Un erreur s'est produit.",
            confirmText: "Fermer",
          );
        },
        context: context,
      );
    }
  }
 Future<String> getEncodedCompanyAddress(CompanyModel model)  async {
String _encodedAddress = "";

model.address = await CompanyAddressDAO().getCompanyAddress(
  model.id,
);

_encodedAddress = model.details.title +
    ", " +
    model.address.street +
    ", " +
    model.address.city +
    ", " +
    model.address.state;

_encodedAddress = Uri.encodeFull(_encodedAddress);

_encodedAddress = _encodedAddress.replaceAll("%20", "+");

return _encodedAddress;
我正在开发一个颤振应用程序,但可能所有设备和平台的请求都是相同的,因此它不是真正针对颤振的

我想显示路线上公司/地点的名称

它可以是web请求,也可以是使用Google Maps移动应用程序URL方案的请求

这就是我目前正在做的,坐标


  Future<void> launchGoogleMaps(BuildContext context) async {
    Position userLocation = await Geolocator().getLastKnownPosition(
      desiredAccuracy: LocationAccuracy.bestForNavigation,
    );

    String googleMapsAppUrl = 'comgooglemapsurl://?';

    if (customFirstPlace != null) {
      googleMapsAppUrl +=
          "saddr=${customFirstPlace.latitude},${customFirstPlace.longitude}";
    } else if (!shouldStartWithUserLocation) {
      googleMapsAppUrl +=
          "saddr=${circuitCompanies[0].lat},${circuitCompanies[0].lng}";
    }

    String googleMapsWebUrl = "http://www.google.com/maps/dir";
    googleMapsWebUrl += "/${userLocation.latitude},${userLocation.longitude}";

    circuitCompanies.forEach((CompanyModel element) {
      int elementIndex = circuitCompanies.indexOf(element);
      // If it's the first element, the "direction"
      // parameter will be added to specify the beginning.
      // If not, the "to" parameter will be added
      // to specify a waypoint (a stop).

      if (elementIndex == 0) {
        googleMapsAppUrl += "&daddr=${element.lat},${element.lng}";
      } else {
        googleMapsAppUrl += "+to:${element.lat},${element.lng}";
      }

      googleMapsWebUrl += "/${element.lat},${element.lng}";
    });

    if (await canLaunch("comgooglemaps://")) {
      print('launching com googleUrl $googleMapsAppUrl');
      await launch(googleMapsAppUrl);
    } else if (await canLaunch(googleMapsWebUrl)) {
      print('launching web url $googleMapsWebUrl');
      await launch(googleMapsWebUrl);
    } else {
      showDialog(
        builder: (_) {
          return SingleActionDialog(
            title: "Erreur",
            onConfirmTap: () => Navigator.pop(context),
            bodyText: "Un erreur s'est produit.",
            confirmText: "Fermer",
          );
        },
        context: context,
      );
    }
  }
 Future<String> getEncodedCompanyAddress(CompanyModel model)  async {
String _encodedAddress = "";

model.address = await CompanyAddressDAO().getCompanyAddress(
  model.id,
);

_encodedAddress = model.details.title +
    ", " +
    model.address.street +
    ", " +
    model.address.city +
    ", " +
    model.address.state;

_encodedAddress = Uri.encodeFull(_encodedAddress);

_encodedAddress = _encodedAddress.replaceAll("%20", "+");

return _encodedAddress;

未来启动GoogleMaps(BuildContext上下文)异步{
Position userLocation=等待地理定位器()。getLastKnownPosition(
期望精度:定位精度。最佳导航,
);
字符串googleMapsAppUrl='comgooglemapsurl://?';
if(customFirstPlace!=null){
谷歌地图+=
“SADD=${customFirstPlace.latitude},${customFirstPlace.latitude}”;
}否则如果(!shouldStartWithUserLocation){
谷歌地图+=
“SADD=${CircuitCompanys[0].lat},${CircuitCompanys[0].lng}”;
}
字符串googleMapsWebUrl=”http://www.google.com/maps/dir";
googleMapsWebUrl+=“/${userLocation.latitude},${userLocation.latitude}”;
circuitCompanys.forEach((CompanyModel元素){
int-elementIndex=circuitCompanys.indexOf(元素);
//如果是第一个元素,“方向”
//将添加参数以指定开头。
//否则,将添加“to”参数
//指定航路点(站点)。
if(elementIndex==0){
googleMapsAppUrl+=“&daddr=${element.lat},${element.lng}”;
}否则{
googleMapsAppUrl+=“+收件人:${element.lat},${element.lng}”;
}
googleMapsWebUrl+=“/${element.lat},${element.lng}”;
});
如果(等待canLaunch(“谷歌地图:/”){
打印(“启动com googleUrl$googleMapsAppUrl”);
等待发布(谷歌地图网址);
}否则(等待canLaunch(谷歌地图搜索)){
打印(“启动web url$googleMapsWebUrl”);
等待发射(谷歌地图);
}否则{
显示对话框(
建筑商:(){
返回SingleActionDialog(
标题:“Erreur”,
onConfirmTap:()=>Navigator.pop(上下文),
正文:“这是一个错误的产品。”,
确认文本:“费尔默”,
);
},
上下文:上下文,
);
}
}
我如何用用户将要去的地方的名称来显示适当的路线,而不是只显示坐标?我也有确切的地址


谢谢

我设法解决了这个问题。我使用了谷歌地图API提供的web URL

我做了一个函数,它按照谷歌地图标准返回地点的地址,而不是仅仅传递坐标


  Future<void> launchGoogleMaps(BuildContext context) async {
    Position userLocation = await Geolocator().getLastKnownPosition(
      desiredAccuracy: LocationAccuracy.bestForNavigation,
    );

    String googleMapsAppUrl = 'comgooglemapsurl://?';

    if (customFirstPlace != null) {
      googleMapsAppUrl +=
          "saddr=${customFirstPlace.latitude},${customFirstPlace.longitude}";
    } else if (!shouldStartWithUserLocation) {
      googleMapsAppUrl +=
          "saddr=${circuitCompanies[0].lat},${circuitCompanies[0].lng}";
    }

    String googleMapsWebUrl = "http://www.google.com/maps/dir";
    googleMapsWebUrl += "/${userLocation.latitude},${userLocation.longitude}";

    circuitCompanies.forEach((CompanyModel element) {
      int elementIndex = circuitCompanies.indexOf(element);
      // If it's the first element, the "direction"
      // parameter will be added to specify the beginning.
      // If not, the "to" parameter will be added
      // to specify a waypoint (a stop).

      if (elementIndex == 0) {
        googleMapsAppUrl += "&daddr=${element.lat},${element.lng}";
      } else {
        googleMapsAppUrl += "+to:${element.lat},${element.lng}";
      }

      googleMapsWebUrl += "/${element.lat},${element.lng}";
    });

    if (await canLaunch("comgooglemaps://")) {
      print('launching com googleUrl $googleMapsAppUrl');
      await launch(googleMapsAppUrl);
    } else if (await canLaunch(googleMapsWebUrl)) {
      print('launching web url $googleMapsWebUrl');
      await launch(googleMapsWebUrl);
    } else {
      showDialog(
        builder: (_) {
          return SingleActionDialog(
            title: "Erreur",
            onConfirmTap: () => Navigator.pop(context),
            bodyText: "Un erreur s'est produit.",
            confirmText: "Fermer",
          );
        },
        context: context,
      );
    }
  }
 Future<String> getEncodedCompanyAddress(CompanyModel model)  async {
String _encodedAddress = "";

model.address = await CompanyAddressDAO().getCompanyAddress(
  model.id,
);

_encodedAddress = model.details.title +
    ", " +
    model.address.street +
    ", " +
    model.address.city +
    ", " +
    model.address.state;

_encodedAddress = Uri.encodeFull(_encodedAddress);

_encodedAddress = _encodedAddress.replaceAll("%20", "+");

return _encodedAddress;
未来getEncodedCompanyAddress(公司模型)异步{
字符串_=”;
model.address=await companyaddress dao().getCompanyAddress(
model.id,
);
_encodedAddress=model.details.title+
", " +
街道+
", " +
模型、地址、城市+
", " +
model.address.state;
_encodedAddress=Uri.encodeFull(_encodedAddress);
_encodedAddress=\u encodedAddress.replaceAll(“%20”和“+”);
返回(u);;
}

现在,谷歌地图应用程序的方向显示了实际的地名,而不是只显示坐标