Tag: 位置

LocationManager在Android中的位置返回null

我在设备上测试我的Android应用程序,当我使用时它总是失败 locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); currentLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); 但是,如果我使用NETWORK_PROVIDER而不是GPS_PROVIDER,它可以工作。 currentLocation返回null。 我怎么处理这个? 我需要在locationListener中添加任何具体内容吗? 谢谢!

获取特定像素的x,y位置

我遇到了一个问题,我得到了一个代码,它读取所有像素并获取像素的RGB颜色。 但在此之前,我将图片切成块,这样我也可以计算出更大的图像,而不会超出内存。 这是代码: Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED); try { decoder_image = BitmapRegionDecoder.newInstance(filePath, false); } catch (IOException e) { e.printStackTrace(); } try { boolean bool_pixel = true; final int width = decoder_image.getWidth(); final int height = decoder_image.getHeight(); // Divide the bitmap into 1100×1100 sized chunks and process it. // This makes sure that the app will not be “overloaded” […]

android – 获取位置并仅在条件为真时将数据发送到远程服务器

我正在构建一个需要将用户位置发送到远程服务器的应用程序(在本例中为Pusher)。 目标是近乎实时地更新他们在地图上的位置,但仅限于他们在工作时,否则应用程序将不需要跟踪他们的位置。 如果他们离开他们接受工作的活动(因此被放置在地图上)并且他们完全离开应用程序,我需要位置更新保持活动状态。 一旦他们到达目的地,我希望停止此背景跟踪。 我一直在关注Android的Service组件,但我不确定它是否是我需要的。 更新应无限期地在后台进行,但仅在用户被分配到作业时(更新在他们接受作业时开始,在到达目的地时结束)。 Bound服务会是最好的吗? 如果是这样,那么与此问题相关的一些代码将非常受欢迎,因为我能找到的很多内容都是通用的,并且可以返回随机整数。 这是我希望在后台执行的代码: package com.example.locationtester; import android.content.Context; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.widget.TextView; import android.widget.Toast; import com.pusher.client.Pusher; import com.pusher.client.PusherOptions; import com.pusher.client.channel.PrivateChannel; import com.pusher.client.channel.PrivateChannelEventListener; import com.pusher.client.connection.ConnectionEventListener; import com.pusher.client.connection.ConnectionState; import com.pusher.client.connection.ConnectionStateChange; import com.pusher.client.util.HttpAuthorizer; import org.json.JSONException; import org.json.JSONObject; public class MainActivity extends AppCompatActivity { […]

getLastKnownLocation()始终返回null,所有提供者都是DummyLocationProvider

我看过很多关于这个问题的post,但没有一个为我提供解决方案。 我试图通过GPS(或最终,任何其他有效的提供商)获得用户位置。 但我总是得到零位置。 我确实得到了一张地图,并且可以设置一个任意位置,是不起作用的提供者。 我正确设置了我的MAPS键 (也检查了它是正确的),所有必要的权限设置( android.permission.INTERNET , android.permission.ACCESS_COARSE_LOCATION , android.permission.ACCESS_FINE_LOCATION ),事实上,所有似乎都在工作昨天很好! 我尝试使用此代码获取所有可能的提供程序: List providers = locManager.getAllProviders(); for (String provider : providers) { printProvider(provider); } 这显示了所有提供者(在我的情况下为4)是DummyLocationProviders。 我试图在手机上运行我的应用程序,而不是模拟器 (虽然我也尝试使用模拟器,启用GPS,但无济于事)。 这是我用来获取位置的代码(昨天工作得很好): //Get criteria Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); //Get best provider String bestProvider = locManager.getBestProvider(criteria, false); printProvider(bestProvider); //get the current location (last known location) from the […]

Android服务不更新位置

我需要每1分钟和每5米位移更新融合位置(我知道它的不良做法,但为了测试和显示在日志中)我开始服务按钮按下按钮按下我在logcat中获得位置但是只有一次。 根据服务类 , onLocationChanged应该每隔1分钟调用一次,但它几乎不会再次调用,即使我的GPS几乎每分钟都开启,然后在关闭之后关闭,但Logcat中仍然没有位置更新。我需要服务类来保持更新位置而不影响UI或主线程 这是logcat,它只显示一次位置更新 09-16 03:13:37.125 10419-10419/com.example.com.pro_working1 D/===Location Service===: Service onConnected Calling 09-16 03:13:37.125 10419-10419/com.example.com.pro_working1 D/===Location Service===: Start Location Update is Calling 09-16 03:13:38.315 10419-10419/com.example.com.pro_working1 D/===Location Service===: Service OnLocationChanged Calling 09-16 03:13:38.315 10419-10419/com.example.com.pro_working1 D/===Location Service===: Here is Updated Locations: Latitude 28.5XXXXX Longitude 77.2XXXXX 09-16 03:13:38.315 10419-10419/com.example.com.pro_working1 D/===Location Service===: Sending Location Starting Accuracy is: 37.5 […]

获取Android Studio应用中的当前位置

我正在开发我的第一个Android应用程序,它应该获取Android设备的经度和经度 ,并通过Web服务将其发送到模板文档。 我按照http://developer.android.com/training/location/retrieve-current.html获取位置的指南。 这是我的.java类的代码: import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.location.Location; import android.location.LocationManager; import android.os.Bundle; import android.provider.Settings; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.EditText; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.location.LocationServices; public class GetLocation extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener { private GoogleApiClient mGoogleApiClient; EditText textLat; EditText textLong; EditText lat; EditText lon; protected void onCreate(Bundle […]

Android模拟器,查找模拟用户位置坐标。 有问题

嘿伙计们,我在尝试查找用户的经度和位置时遇到了麻烦,因为我运行程序并为模拟位置设置了genet修复的telnet命令。 在模拟器运行时,我只为模拟器设置模拟坐标,使其无响应,并且我的程序在检测输入坐标时失败。 import android.app.Activity; import android.content.Context; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.location.LocationProvider; import android.os.Bundle; import android.widget.TextView; import android.widget.Toast; public class LBSact extends Activity{ /** Called when the activity is first created. */ public double longitude; public double latitude; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); longitude = 0; latitude = 0; //Creating the […]

Google Play服务中的LocationRequest不会更新,间隔设置为小于1秒。

我正在开发一个Android应用程序,我需要在其中显示每秒30-40次更新的位置更新。 我正在使用Google I / O 2013中引入的Google Play服务的位置API 。它使用融合位置提供商(利用加速度计和其他传感器以及GPS)来实现更准确,更有效的位置跟踪。 这是我的代码: protected void startLocationTracking() { if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(this)) { mLocationClient = new LocationClient(this, mConnectionCallbacks, mConnectionFailedListener); mLocationClient.connect(); } } private ConnectionCallbacks mConnectionCallbacks = new ConnectionCallbacks() { @Override public void onDisconnected() { } @Override public void onConnected(Bundle arg0) { LocationRequest locationRequest = LocationRequest.create(); locationRequest.setFastestInterval(0); locationRequest.setInterval(0).setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); mLocationClient.requestLocationUpdates(locationRequest, mLocationListener); } }; private […]

在Java中的非活动窗口上的某个位置模拟鼠标点击?

无论如何,我正在构建一个在后台运行的机器人。 这个机器人要求我点击。 当然,我希望能够在机器人运行时做其他事情。 所以我想知道我是否可以在非活动窗口的某个位置模拟鼠标点击。 如果可以的话,如果你们中的任何一个人能帮助我,我将不胜感激。

边界框中的itext多行文本

有没有人知道,如何在iText中在边界框中添加多行文字(指定坐标)。 我试过了 cb.showTextAligned( PdfContentByte.ALIGN_LEFT, text, bounds.getLeft(), TOTAL_HEIGHT-bounds.getTop(), 0 ); 但它不支持换行。 我也试过了 PdfContentByte cb = writer.getDirectContent(); cb.moveText(300,400); document.add(new Paragraph(“TEST paragraph\nNewline”)); 这支持换行但不对moveText作出反应,因此我不知道如何将它放在给定位置或更好:边界框。 我怀疑块或PdfTemplate或者表可能有帮助,但我(还)不知道如何把它放在一起。 TIA寻求帮助。