【问题标题】:getting negative values of latitude and longitude获得纬度和经度的负值
【发布时间】:2018-08-01 06:09:52
【问题描述】:

我想在我的应用程序中获取经度和纬度的值,我已经做到了,但问题是我得到带有值的负号。虽然值是正确的,但不知道为什么要得到带有值的负号。

java类代码:

package com.vshine.neuron.testing;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

public class code extends AppCompatActivity implements LocationListener {
    private TextView textView;
    private LocationManager locationManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_code);
        textView = findViewById(R.id.tv);
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

         if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
         // TODO: Consider calling
         //    ActivityCompat#requestPermissions
         // here to request the missing permissions, and then overriding
         //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
         //                                          int[] grantResults)
         // to handle the case where the user grants the permission. See the documentation
         // for ActivityCompat#requestPermissions for more details.
         return;
         }
         Location location = locationManager.getLastKnownLocation(locationManager.NETWORK_PROVIDER);
         onLocationChanged(location);
         }

@Override
public void onLocationChanged(Location location) {
        double longitude = location.getLongitude();
        double latitude = location.getLatitude();
        textView.setText("Longitude: " + longitude + "\n\n" + "Latitude: " + latitude);

        }

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {

        }

@Override
public void onProviderEnabled(String provider) {

        }

@Override
public void onProviderDisabled(String provider) {

        }
        }

【问题讨论】:

  • 纬度和经度坐标可以采用负值,例如,参见this MSDN article,其中讨论了这一点。不,您的代码没有损坏。
  • @TimBiegeleisen 问题是当我输入这些 LatLong 时我没有得到 mylocation 意味着我没有得到正确的 LatLong?

标签: android android-location


【解决方案1】:

Latitude 和 Longitude 可以有负值。

你的代码很好

Check any ref

【讨论】:

  • 问题是当我输入这些 LatLong 时我没有得到 mylocation 意味着我没有得到正确的 LatLong?
  • 您的设备位置是否启用?
  • 我在电脑模拟器上测试这个
  • 来自模拟器设置。您可以设置所需的纬度和经度。在模拟器中使用时。你不会得到当前位置。您将获得设置中设置的位置
  • 您是如何解决问题的。请发布它,以便其他有同样问题的人得到帮助。
【解决方案2】:

纬度表示赤道的北部和南部。经度表示本初子午线的东面和西面。

负纬度表示赤道以南,负经度表示本初子午线以西。

位置数据通常以纬度和经度对的形式表示,如下所示:

37.427619, -122.166972 [胡佛塔,斯坦福大学]

下面的简单框架可以帮助您解码位置对。

+ + : North and East 
+ - : North and West 
- - : South and West 
- + : South and East

请注意,此框架的中心点是几内亚湾的本初子午线和赤道相交处的 0,0。

答案取自 Quora。 Quora Link

【讨论】:

  • 你能告诉我应该在我的代码中更改什么以获得正值吗?
【解决方案3】:

LatLong 可以是正面的也可以是负面的。

示例:
44.389061321549, -114.659369144245 是美国爱达荷州的有效LatLong。

只需复制您的经纬度并将其粘贴到Google Maps 的搜索框中,您将获得经纬度的准确位置。

【讨论】:

  • 这就是我放这些 LatLong 时没有得到 mylocation 的问题
  • 你得到了什么 LatLong?
  • -34.7868114 , -55.2337042
  • 如果您在模拟器上运行应用程序,这可能是您的模拟器设置中的默认LatLong -> 位置
  • 我的模拟器中的默认值不同,我已经检查过了
猜你喜欢
  • 2011-08-18
  • 2017-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-06
  • 2019-10-11
  • 1970-01-01
  • 1970-01-01
  • 2015-07-12
相关资源
最近更新 更多