与地图聊天应用程序

时间:2015-03-20 10:07:26

标签: android google-maps chat

我想构建一个包含位置共享的基本聊天应用程序。我精通Java,但在Android平台上没有足够的工作。我该如何处理这个问题以及采取的步骤是什么?

1 个答案:

答案 0 :(得分:0)

通过聊天消息将位置值纬度和经度发送给其他人。您可以通过以下方式获取用户的最后已知位置:

private double[] getGPS()
{
    LocationManager lm = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
    List<String> providers = lm.getProviders(true);

    /* Loop over the array backwards, and if you get an accurate location, then break out the loop */
    Location l = null;

    for (int i = providers.size() - 1; i >= 0; i--)
    {
        l = lm.getLastKnownLocation(providers.get(i));
        if (l != null)
            break;
    }

    double[] gps = new double[2];
    if (l != null)
    {
        gps[0] = l.getLatitude();
        gps[1] = l.getLongitude();
    }
    return gps;
}
相关问题