如何根据当前的经纬度获得时区?

时间:2018-01-23 07:27:47

标签: android

我在地图框中获取当前纬度和经度,我需要基于当前纬度和经度的当前时区。

例如。我的设备时间是美国,但我的位置在印度显示,所以我需要印度时区。你能帮助我。

@Override
    public void onLocationChanged(Location location) {
        try {
            mLatLng = new LatLng(location.getLatitude(), location.getLongitude());
            Log.i("EE","mLatLngmLatLng"+mLatLng);
            String time = new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm:ss.SSS").format(location.getTime());

            Log.i("EE","time----"+time);
            Log.i("EE","vlocation.getTime()----"+location.getTime());

            updateCamera();
            if (mMarker != null) {
                updateMarker();
            }else{
                addMarker();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

1 个答案:

答案 0 :(得分:0)

通过Geocoder获取地址并确定国家/地区,当您获得国家/地区名称时,您可以轻松识别时区。

public override View GetView(int position, View convertView, ViewGroup parent)
{
    var view = convertView;

    if (view == null)
    {
        view = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.list_view_dataTemplate, parent, false);

        var txtName = view.FindViewById<TextView>(Resource.Id.textView1);
        var txtAge = view.FindViewById<TextView>(Resource.Id.textView2);
        var txtEmail = view.FindViewById<TextView>(Resource.Id.textView3);
        var button1 = view.FindViewById<Button>(Resource.Id.button1);

        var viewHolder = new ViewHolder() { txtName = txtName, txtAge = txtAge, txtEmail = txtEmail, button1 = button1 };
        view.Tag = viewHolder;

        button1.Click += (sender, args) => {
            viewHolder.ShowToast();
        };

    }

    var holder = (ViewHolder)view.Tag;

    holder.txtName.Text = "name " + position;
    holder.txtAge.Text = "age " + position;
    holder.txtEmail.Text = "email " + position;
    holder.position = position;

    return view;
}