Tag: gps

如何确定GPS坐标是否位于矩形区域内?

我在Stackoverflow和其他网站上经历了许多类似的问题,我的解决方案基于这些答案,但我仍然无法让它工作…… 我的问题:我想确定某个GPS位置P位于由四个给定的GPS坐标A , B , C , D界定的矩形区域内。 目前我正在计算三角形ABP , BCP , CDP和DAP的面积。 如果这些区域中的任何一个大于零(不要沮丧,数学家),那么这个点就在我的矩形之外。 码: private static double triangleArea(Location a, Location b, Location c) { // (Cx*By-Bx*Cy)-(Cx*Ay-Ax*Cy)+(Bx*Ay-Ax*By) double result = (c.getLongitude()*b.getLatitude()-b.getLongitude()*c.getLatitude())-(c.getLongitude()*a.getLatitude()-a.getLongitude()*c.getLatitude())+(b.getLongitude()*a.getLatitude()-a.getLongitude()*b.getLatitude()); return result; } public static boolean isInsideSquare(Location a, Location b, Location c, Location d, Location p) { if (triangleArea(a,b,p)>0 || triangleArea(b,c,p)>0 || triangleArea(c,d,p)>0 || […]

Android通过位置管理器获取经度和纬度

我正在尝试使用位置管理器获取用户位置,但该位置始终返回null。 我也要求用户打开gps。 这是我的代码: int permisioncheck = ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION); if(permisioncheck == 0){ lm = (LocationManager)getContext().getSystemService(Context.LOCATION_SERVICE); List providers = lm.getProviders(true); Location bestLocation = null; for (String provider : providers) { Location location = lm.getLastKnownLocation(provider); if (location == null) { continue; } if (bestLocation == null || location.getAccuracy() < bestLocation.getAccuracy()) { // Found best last known location: %s", […]

难以将用户1的位置发送给用户2,将用户2的位置发送给用户1?

我有一个代码将用户1的位置发送给用户2,用户2的位置发送给用户1。 用户1的位置完美地发送给用户2,用户2甚至向用户1发送消息,但是它发送的位置是用户1的位置而不是他(用户2)的位置。 这是我的代码: package com.example.gui; import android.app.Activity; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.location.Geocoder; import android.location.Location; import android.location.LocationManager; import android.net.Uri; import android.os.Bundle; import android.telephony.SmsManager; import android.telephony.SmsMessage; import android.util.Log; import android.view.View; import android.widget.Toast; public class ReceivelocationActivity extends BroadcastReceiver { private static final String TAG = “LocationActivity”; public […]

模拟GPS位置问题

我正在开发一个获取用户指定的纬度,经度和海拔高度的APP,然后在手机上伪造这个GPS位置,并显示我在谷歌地图中的那个位置。 我对清单文件具有所需权限,并且在开发人员设置中启用了模拟位置。 LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); //lm.clearTestProviderEnabled(mocLocationProvider); lm.addTestProvider(mocLocationProvider, false, false, false, false, false, false, false, 0, 10); lm.setTestProviderEnabled(mocLocationProvider, true); mockLocation = new Location(mocLocationProvider); // a string mockLocation.setLatitude(Integer.parseInt(latitude.getText().toString())); // double mockLocation.setLongitude(Integer.parseInt(longitude.getText().toString())); mockLocation.setAltitude(Integer.parseInt(altitude.getText().toString())); mockLocation.setTime(System.currentTimeMillis()); lm.setTestProviderLocation( mocLocationProvider, mockLocation); 但看起来我的GPS位置在谷歌地图上根本没有改变,有什么问题? 更新:我刚刚在我的手机上安装了一个名为“伪GPS位置”的应用程序,该应用程序工作正常,但我仍然不知道我的代码有什么问题,但我认为我的正式方法是实现这一点。 更新#2:虽然一些类似的应用程序可以在我的手机上运行,​​但我发现了一些例外, http://www.cowlumbus.nl/forum/MockGpsProvider.zip ,这个应用程序无法在我的手机上运行。 有人可以帮我解决这个问题吗? 数百万的谢谢! 每次设置位置时我都没有收到任何错误消息。 更新#3:我注意到这个应用程序相当陈旧,所以它不能在4.1上运行。 如果是这样,如何在新版本中做同样的事情? 我的手机是三星galaxy s3,希望它有所帮助。 更新#4:对于您的信息,我的更新#2中的应用程序代码是: package nl.cowlumbus.android.mockgps; import java.io.BufferedReader; import java.io.InputStream; […]

如何在Android中每分钟获得gps坐标?

我希望每分钟都能得到我的坐标,即使用户没有移动。 所以我使用requestLocationUpdates和以下参数: locMgr.requestLocationUpdates( LocationManager.GPS_PROVIDER, 60000, // minTime in ms 0, // minDistance in meters PosljiLokacijo.this); 但是当我在我的HTC Hero(2.1 Android)上测试它并且我没有移动时,onLocationChanged()从未被调用。 如果我将minDistance更改为1,那么我会在开始时获得一些更新但在此之后,它们会以非常不规则的间隔进行。 我应该如何选择这两个参数(minTime和minDistance)来每分钟接收坐标?

如何在android中以编程方式启用/禁用gps和移动数据?

我希望我的应用程序能够以编程方式启用/禁用gps和移动数据,因为有许多应用程序,如tasker,profile flow,lookout extra,这可以做到这一点,所以我搜索它但没有找到任何有用的例子,我发现以下代码,但他们没有工作。 private void setMobileDataEnabled(Context context, boolean enabled) { final ConnectivityManager conman = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final Class conmanClass = Class.forName(conman.getClass().getName()); final Field iConnectivityManagerField = conmanClass.getDeclaredField(“mService”); iConnectivityManagerField.setAccessible(true); final Object iConnectivityManager = iConnectivityManagerField.get(conman); final Class iConnectivityManagerClass = Class.forName(iConnectivityManager.getClass().getName()); final Method setMobileDataEnabledMethod = iConnectivityManagerClass.getDeclaredMethod(“setMobileDataEnabled”, Boolean.TYPE); setMobileDataEnabledMethod.setAccessible(true); setMobileDataEnabledMethod.invoke(iConnectivityManager, enabled); } private void turnGPSOn(){ String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED); […]

如何计算Java中两个gps点之间的距离?

我使用了这段代码,但它不起作用: 需要两个gps坐标之间的距离,如41.1212,11.2323(公里)(Java) double d2r = (180 / Math.PI); double distance = 0; try{ double dlong = (endpoint.getLon() – startpoint.getLon()) * d2r; double dlat = (endpoint.getLat() – startpoint.getLat()) * d2r; double a = Math.pow(Math.sin(dlat / 2.0), 2) + Math.cos(startpoint.getLat() * d2r) * Math.cos(endpoint.getLat() * d2r) * Math.pow(Math.sin(dlong / 2.0), 2); double c = 2 * Math.atan2(Math.sqrt(a), […]

在Android M中获取纬度和经度0.0

我在Android Marshmallow(API 23)即6.0中获得了价值0.0作为纬度和经度的问题。 我已经搜索了很多关于这个,但没有找到它的解决方案。 我的代码完全适用于小于23的其他API版本。 我也把selfPermission的代码和所有正在运行的代码放在一起,而不是它给我0.0很晚和很长。 请看看我关注的方式: GPSTracker.java public class GPSTracker extends Service implements LocationListener { private Context mContext; // Flag for GPS status boolean isGPSEnabled = false; // Flag for network status boolean isNetworkEnabled = false; // Flag for GPS status boolean canGetLocation = false; Location location; // Location double latitude; // Latitude double […]

更快速地计算两点之间的地理距离

我从互联网上的某个地方借用了以下方法(不记得在哪里)。 但它正在做一个直接的过程,找到两个GPS点之间的距离。 它运行得很好,除了它可能有点慢,因为我在数百万点运行它。 我想知道是否有人知道一种计算上更便宜的方法。 准确度需要在“正确”的一般区域,但不需要100%准确。 private double distFrom(double lat1, double lng1, double lat2, double lng2) { double earthRadius = 3958.75; double dLat = Math.toRadians(lat2-lat1); double dLng = Math.toRadians(lng2-lng1); double a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * Math.sin(dLng/2) * Math.sin(dLng/2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); return earthRadius * c; } } […]

获取Android上的当前GPS位置

我试图通过GPSfunction获取用户的当前位置, 写了一个实现LocationListener的简单类 public class LocationManagerHelper implements LocationListener { private static double latitude; private static double longitude; @Override public void onLocationChanged(Location loc) { latitude = loc.getLatitude(); longitude = loc.getLongitude(); } @Override public void onProviderDisabled(String provider) { } @Override public void onProviderEnabled(String provider) { } @Override public void onStatusChanged(String provider, int status, Bundle extras) { // TODO […]