ANDROID - 检索坐标并在Google地图上显示

问题描述:

我正在接收包含我需要的数据的短信,例如纬度和经度。我已成功解析SMS正文并保存到数据库中。我想检索存储的坐标并将其显示在Google地图上。



我尝试了什么:



I am receiving SMS containing the data I needed such as latitude and longitude. I have successfully parse the SMS body and saved in into the database. I wanted to retrieve the stored coordinates and display it on Google Map.

What I have tried:

I am new to Android. Can you advice me what to do?

这是一种方法:

Here's one way to do this:
// Create a Uri from an intent string. Use the result to create an Intent.
// Example latitude = 46.414382, longitude = 10.013988
Uri gmmIntentUri = Uri.parse("google.streetview:cbll=46.414382,10.013988");

// Create an Intent from gmmIntentUri. Set the action to ACTION_VIEW
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);

// Make the Intent explicit by setting the Google Maps package
mapIntent.setPackage("com.google.android.apps.maps");

// Attempt to start an activity that can handle the Intent
startActivity(mapIntent);



请参阅: 适用于Android的Google地图意图  | 地图网址  |  Google Developers [ ^ ]



/ ravi


See: Google Maps Intents for Android  |  Maps URLs  |  Google Developers[^]

/ravi


你需要使用谷歌地图SDK for Android,因为你有得到latlong坐标,你可以使用Java代码来渲染它。



请记住,您需要有一个Google Maps API密钥才能生效,因为Google的原生地图应用需要您从意图 - 你不会控制超出那个阶段的任何东西。



查看此页面以了解如何为Google地图指定标记:标记  | 适用于Android的Maps SDK  |  Google Developers [ ^ ] ,最简单的代码就好了,

You would need to use the Google Maps SDK for Android for that, since you have gotten the latlong coordinates, you can use the Java code to render that.

Remember that you need to have a Google Maps API key for this to work, as Google's native Maps app would need you to call it from an Intent—and you do not control anything beyond that stage.

Check this page to know how to assign markers to the Google Maps: Markers  |  Maps SDK for Android  |  Google Developers[^], simplest of the code would be like,
// Code copied from the link above
private static final LatLng PERTH = new LatLng(-31.952854, 115.857342);
private static final LatLng SYDNEY = new LatLng(-33.87365, 151.20689);
private static final LatLng BRISBANE = new LatLng(-27.47093, 153.0235);

@Override
public void onMapReady(GoogleMap map) {
    mMap = map;

    // Add some markers to the map, and add a data object to each marker.
    mPerth = mMap.addMarker(new MarkerOptions()
                .position(PERTH)
                .title("Perth");
    mPerth.setTag(0);

    mSydney = mMap.addMarker(new MarkerOptions()
                .position(SYDNEY)
                .title("Sydney");
    mSydney.setTag(0);

    mBrisbane = mMap.addMarker(new MarkerOptions()
                .position(BRISBANE)
                .title("Brisbane");
    mBrisbane.setTag(0);

    // Set a listener for marker click.
    mMap.setOnMarkerClickListener(this);
}

你需要提供自己坐标的位置值在数据库中。



在此处阅读Google Maps SDK for Android的完整指南,概述  |  Google地图SDK for Android  |  Google Developers [ ^ ]

You need to provide the position values for your own coordinates that you have in the database.

Read the complete guide for Google Maps SDK for Android here, Overview  |  Maps SDK for Android  |  Google Developers[^]