简体   繁体   English

Android中的Google Maps API

[英]Google maps API in Android

我正在尝试实现一种功能,以便当用户在文本字段中输入地址并单击按钮时,该地址应复制到Google地图的目标字段中,并且用户位置应设置为“我的位置”(他的当前位置)。

You can open google map in following way: 您可以通过以下方式打开Goog​​le地图:

String CURRENT_LOCATION = "current_location_latitude, current_location_longitude";
String DESTINATION_LOCATION = "address_from_your_text_view";

Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr="+ CURRENT_LOCATION +" daddr="+DESTINATION_LOCATION));
startActivity(intent);

Note: You should get device/user current location from LocationManager 注意:您应该从LocationManager获取设备/用户的当前位置

In order to show route on Google Map, Just call an intent which passes current and destination latitude and longitude. 为了在Google Map上显示路线,只需调用一个意图即可传递当前和目的地的纬度和经度。 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. 完成此操作后,其Google Map的工作将显示位置。 You may also show street view. 您也可以显示街景。

In below code, there are three parameters : current_lat, current_longi, dest_address 在下面的代码中,有三个参数: 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. 当您调用此意图时,Google Map会显示是通过公共汽车还是步行绘制路线的选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM