将位置发送到 google 带有纬度和经度的地图
sending location to google map with latitude and longitude
这就是我获取当前位置的方式。现在我的问题是,有什么方法可以使这个纬度和经度成为 link 用户可以单击的地方,当前位置将显示在 GoogleMap 上。因为我将通过短信将此 link 发送给另一个 android,当他点击 link Google 时,他手机中的地图安装将打开或 Google地图网站将打开,通过 lang 和 lat 获得的位置将显示在地图上。不知道如何实现它有什么帮助吗?
public void onLocationChanged(Location location) {
mLocationView.setText("Location received: "+ location.getLatitude() + location.getLongitude());
使用下面的代码
String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
context.startActivity(intent);
要构造一个可以添加到 SMS 消息的简单 URL,您可以这样做:
String link = "http://maps.google.com/maps?q=loc:" + String.format("%f,%f", location.getLatitude() , location.getLongitude() );
例如,这段代码:
double lat = 37.77657;
double lon = -122.417506;
String link = "http://maps.google.com/maps?q=loc:" + String.format("%f,%f", lat, lon);
像这样构造一个link:
http://maps.google.com/maps?q=loc:37.776570,-122.417506
有关详细信息,请参阅 this question。
这就是我获取当前位置的方式。现在我的问题是,有什么方法可以使这个纬度和经度成为 link 用户可以单击的地方,当前位置将显示在 GoogleMap 上。因为我将通过短信将此 link 发送给另一个 android,当他点击 link Google 时,他手机中的地图安装将打开或 Google地图网站将打开,通过 lang 和 lat 获得的位置将显示在地图上。不知道如何实现它有什么帮助吗?
public void onLocationChanged(Location location) {
mLocationView.setText("Location received: "+ location.getLatitude() + location.getLongitude());
使用下面的代码
String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
context.startActivity(intent);
要构造一个可以添加到 SMS 消息的简单 URL,您可以这样做:
String link = "http://maps.google.com/maps?q=loc:" + String.format("%f,%f", location.getLatitude() , location.getLongitude() );
例如,这段代码:
double lat = 37.77657;
double lon = -122.417506;
String link = "http://maps.google.com/maps?q=loc:" + String.format("%f,%f", lat, lon);
像这样构造一个link:
http://maps.google.com/maps?q=loc:37.776570,-122.417506
有关详细信息,请参阅 this question。