谷歌地图API中的Andr​​oid地图、API、oid、Andr

2023-09-06 10:58:22 作者:柚稚少年

我想实现一个功能,例如,当用户输入文本字段,并点击了一个按钮,一个地址,该地址应该被复制到谷歌地图的目的地字段和用户位置应设置为我的位置(他目前的位置)。

I am trying to implement a functionality such that when a user enters an address in a text field and clicks on a button, that address should be copied into the destination field of Google maps and the user location should be set to "My Location" (his current location).

推荐答案

为了显示在谷歌地图的路线,只需拨打这通电流和目标的经度和纬度的意图。您也可以在任何情况下,通过地址,如果不知道LAT-长。这样做了以后,它的谷歌地图的任务,以显示位置。您也可以显示街景。

In order to show route on Google Map, Just call an intent which passes current and destination latitude and longitude. You may also pass address in any case if don't know lat-long. After doing this, its Google Map's job to show location. You may also show street view.

在低于code,有三个参数: current_lat,current_longi,DEST_ADDRESS

In below code, there are three parameters : current_lat, current_longi, dest_address

 final Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?" 
+ "saddr="+ current_lat+","+current_longi + "&daddr="+dest_address ));

intent.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");

startActivity(intent); 

如果您有当前地址和目的地址,那么你可以这样写:

If you have current address and destination address, then you can write like this :

Uri.parse("http://maps.google.com/maps?" 
+ "saddr="+curr_address+ "&daddr="+dest_address ));

如果您有当前和目标的经度和纬度都那么你可以这样写:

If you have current and destination latitude and longitude both then you can write like this :

Uri.parse("http://maps.google.com/maps?" 
+ "saddr="+ current_lat+","+current_longi + "&daddr="+ destt_lat+","+dest_longi  ));

当你调用这个意图,谷歌地图显示选项是否乘坐公共汽车或步行绘制的路线。

When you call this intent, Google Map shows option whether to draw route by bus or by walk.