在特定坐标处打开地图在Android上不起作用

在特定坐标处打开地图在Android上不起作用,android,google-maps,Android,Google Maps,我正在构建一个应用程序,其功能是向用户的地图应用程序发送特定的预先确定但动态的坐标,以便用户可以追踪到地图的路线 目前,我正在使用: String coordinates = String.format("geo:0,0?q=" + latitude + "," + longitude); Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse(coordinates) ); startActivity( intent ); 但是,当

我正在构建一个应用程序,其功能是向用户的地图应用程序发送特定的预先确定但动态的坐标,以便用户可以追踪到地图的路线

目前,我正在使用:

String coordinates = String.format("geo:0,0?q=" + latitude + "," + longitude);
Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse(coordinates) );
startActivity( intent );
但是,当它打开地图时,我得到的不是请求的位置,而是[latitude]、[latitude]toast和我的当前位置的无结果

这当然不是坐标本身的问题,因为手动搜索坐标工作得很好,打印请求Uri表明其构造正确。令人惊讶的是,只发送两个coords的前两个数字就可以了,虽然不能将我发送到我想发送的地方,但不会给出toast错误消息

在传递值或其他东西时,是否需要进行任何额外的格式化

我使用原始数据,-23.561261和-46.681212,例如,如果这有任何区别,我位于巴西,是的,我必须发送坐标,因为遗憾的是数据与实际地址的格式不一致

更新:事实证明,代码很好,它可以在我的razr-i上运行,但是,在我用于原始测试的Galaxy Express中,它仍然是不可行的

知道发生了什么吗?两台设备都运行Android 4.1.2

您的代码是正确的

您发送的值是双倍的

    double latitude = -23.561261;
    double longitude = -46.681212;
    String coordinates = String.format("geo:0,0?q=" + latitude + "," + longitude);
    Intent intentMap = new Intent( Intent.ACTION_VIEW, Uri.parse(coordinates) );
    startActivity( intentMap );
必须与直接在浏览器中加载url类似:

你的代码是正确的

您发送的值是双倍的

    double latitude = -23.561261;
    double longitude = -46.681212;
    String coordinates = String.format("geo:0,0?q=" + latitude + "," + longitude);
    Intent intentMap = new Intent( Intent.ACTION_VIEW, Uri.parse(coordinates) );
    startActivity( intentMap );
必须与直接在浏览器中加载url类似:


我不太记得错误是什么,因为它已经很久了,但长话短说,下面是工作代码:

String coordinates = "http://maps.google.com/maps?daddr=" + latitude + "," + longitude;

Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse(coordinates) );
startActivity( intent );

我不太记得错误是什么,因为它已经很久了,但长话短说,下面是工作代码:

String coordinates = "http://maps.google.com/maps?daddr=" + latitude + "," + longitude;

Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse(coordinates) );
startActivity( intent );

问题出在现场。如果您的通话格式如下所示,您的代码将适用于任何手机:

String coordinates = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude);

问题出在现场。如果您的通话格式如下所示,您的代码将适用于任何手机:

String coordinates = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude);

是的,显然我做的每件事都是正确的,只是在另一台设备上测试了它,这次是摩托罗拉的razr-I,它的工作原理就像发条一样。然而,在另一台设备上,三星Galaxy Express,我仍然收到了毫无意义的错误信息。是的,显然我做的每件事都是正确的,只是在另一台设备上测试了它,这一次是在摩托罗拉razr-I上,它像钟表一样工作。然而,在另一台设备,三星Galaxy Express上,我仍然收到了荒谬的错误信息。你解决过这个问题吗?我在某些设备上遇到了这个问题。事实上,我解决了。不记得是什么错误,但我只是在我的答案中发布了工作代码;看看它是否仍然重要。你解决过这个问题吗?我在某些设备上确实遇到了这个问题。事实上,我解决了。不记得是什么错误,但我只是在我的答案中发布了工作代码;如果它仍然重要的话,请检查一下。