尽快将用户的当前位置置于阈值内,同时节省电池电量.
首先,android有两个提供商; 网络和GPS.有时网络更好,有时GPS更好.
"更好"是指速度与准确度之比.
如果我几乎可以立即获得位置并且不打开GPS,我愿意牺牲几米精度.
其次,如果您要求更新位置更改,则在当前位置稳定时不会发送任何内容.
谷歌有一个确定"最佳"位置的例子:http://developer.android.com/guide/topics/location/obtaining-user-location.html#BestEstimate
但我认为它不是应该尽可能好的地方/可能.
我有点困惑为什么谷歌没有标准化的位置API,开发者不应该关心位置来自哪里,你应该只指定你想要的东西,手机应该为你选择.
我需要找到一个很好的方法来确定"最佳"位置,也许是一些启发式或者可能通过某些第三方库.
这并不意味着确定最好的提供商!
我可能会使用所有提供商并选择其中最好的.
该应用程序将以固定间隔收集用户的位置(假设每10分钟左右)并将其发送到服务器.
该应用程序应尽可能节省电池,并且位置应具有X(50-100?)米的精度.
目标是以后能够在地图上绘制白天用户的路径,因此我需要足够的准确性.
您认为对于期望和接受的准确度的合理价值是什么?
我一直在使用100米接受,并且根据需要使用30米,这要问多少?
我希望以后能够在地图上绘制用户的路径.
期望100米,接受500米更好吗?
此外,现在我每次更新GPS的时间最长为60秒,如果你在室内的准确度可能超过200米,这个位置太短了吗?
这是我目前的代码,感谢任何反馈(除了缺少错误检查,这是TODO):
protected void runTask() {
final LocationManager locationManager = (LocationManager) context
.getSystemService(Context.LOCATION_SERVICE);
updateBestLocation(locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER));
updateBestLocation(locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER));
if (getLocationQuality(bestLocation) != LocationQuality.GOOD) {
Looper.prepare();
setLooper(Looper.myLooper());
// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
updateBestLocation(location);
if (getLocationQuality(bestLocation) != LocationQuality.GOOD)
return;
// We're done …Run Code Online (Sandbox Code Playgroud) 在构造函数,赋值和方法调用方面,PyCharm IDE非常擅长分析我的源代码并确定每个变量应该是什么类型.我喜欢它,因为它给了我很好的代码完成和参数信息,如果我尝试访问不存在的属性,它会给我警告.
但是当谈到参数时,它什么都不知道.代码完成下拉列表无法显示任何内容,因为它们不知道参数的类型.代码分析无法查找警告.
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
peasant = Person("Dennis", 37)
# PyCharm knows that the "peasant" variable is of type Person
peasant.dig_filth() # shows warning -- Person doesn't have a dig_filth method
class King:
def repress(self, peasant):
# PyCharm has no idea what type the "peasant" parameter should be
peasant.knock_over() # no warning even though knock_over doesn't exist
King().repress(peasant)
# Even if I call the method once with a Person instance, …Run Code Online (Sandbox Code Playgroud) 我想有一个可选参数,如果只有标志存在而没有指定值,则默认为一个值,但是如果用户指定了值,则存储用户指定的值而不是默认值.是否已有针对此的行动?
一个例子:
python script.py --example
# args.example would equal a default value of 1
python script.py --example 2
# args.example would equal a default value of 2
Run Code Online (Sandbox Code Playgroud)
我可以创建一个动作,但想知道是否有现成的方法来执行此操作.
我list在python中有一个文件名,我想构建一个set所有文件名.
filelist=[]
for filename in filelist:
set(filename)
Run Code Online (Sandbox Code Playgroud)
这似乎不起作用.怎么办呢?
我正在尝试使用Mine的代码将日志写入Android文件上的自定义Log.txt文件,但此方法创建文件但不包含任何内容.基本上我想读取文件的先前内容,然后用现有内容附加我的数据.
守则如下:
public static void write(String str)
{
InputStream fileInputStream = null;
FileOutputStream fileOutpurStream = null;
try
{
fileInputStream = new FileInputStream(file);
fileOutpurStream = new FileOutputStream(file);
if(file.exists())
{
int ch = 0;
int current = 0;
StringBuffer buffer = new StringBuffer();
while((ch = fileInputStream.read()) != -1)
{
buffer.append((char) ch);
current++;
}
byte data[]=new byte[(int)file.length()];
fileInputStream.read(data);
fileOutpurStream.write(data);
fileOutpurStream.write(str.getBytes(),0,str.getBytes().length);
fileOutpurStream.flush();
}
else
{
file.createNewFile();
fileOutpurStream.write(str.getBytes(),0,str.getBytes().length);
fileOutpurStream.flush();
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
try
{
fileInputStream.close();
fileOutpurStream.flush();
fileOutpurStream.close();
fileOutpurStream = …Run Code Online (Sandbox Code Playgroud) 我在这里读到,无论如何都不应该将文件保存在服务器中,因为它不是可移植的,事务性的并且需要外部参数.但是,鉴于我需要一个针对tomcat(7)的tmp解决方案,并且我对服务器机器有(相对)控制,我想知道:
保存文件的最佳位置是什么?我应该保存/WEB-INF/uploads(建议不要在这里)或某个地方$CATALINA_BASE(见这里)或......?JavaEE 6教程从用户获取路径(:wtf :).注意:该文件不应以任何方式下载.
我应该建立一个配置参数详见这里?我很欣赏一些代码(我宁愿给它一个相对路径 - 所以它至少是Tomcat可移植的) - Part.write()看起来很有希望 - 但显然需要一个绝对的路径
我对这种方法与数据库/ JCR存储库的缺点的阐述感兴趣
不幸的是 ,@ BalusC 的FileServlet专注于下载文件,而他在上传文件时的答案会跳过保存文件的位置.
容易转换为使用DB或JCR实现(如长耳兔)的解决方案将是优选的.
所以,我有这个问题.我得到了元组(1,2,3),我应该用字符串格式打印.例如.
tup = (1,2,3)
print "this is a tuple %something" % (tup)
Run Code Online (Sandbox Code Playgroud)
这应该用括号打印元组表示,比如
这是一个元组(1,2,3)
但我得到了TypeError: not all arguments converted during string formatting.
我能在世界上做到这一点吗?有点失去了这里,如果你们可以指出我正确的方向:)
在eclipse 3.4.2中编译一个android项目时,我得到的是在构建路径错误得到解决之前无法构建项目.
我 从博客http://www.scottdstrader.com/blog/ether_archives/000921.html获得了一个临时解决方案
决议是强制重新保存所选项目(及其.classpath文件):
我能找到的唯一其他引用是对.classpath文件的内容进行微小的更改.
这个问题有永久性的解决办法吗?
由于os.popen被subprocess.popen取代,我想知道如何转换
os.popen('swfdump /tmp/filename.swf/ -d')
Run Code Online (Sandbox Code Playgroud)
到subprocess.popen()
我试过了:
subprocess.Popen("swfdump /tmp/filename.swf -d")
subprocess.Popen("swfdump %s -d" % (filename)) # NOTE: filename is a variable
# containing /tmp/filename.swf
Run Code Online (Sandbox Code Playgroud)
但我想我没有正确地写出来.任何帮助,将不胜感激.谢谢
我有一个问题,在我的Android应用程序上创建一个目录并将文件保存到它.我正在使用这段代码来执行此操作:
String filename = "MyApp/MediaTag/MediaTag-"+objectId+".png";
File file = new File(Environment.getExternalStorageDirectory(), filename);
FileOutputStream fos;
fos = new FileOutputStream(file);
fos.write(mediaTagBuffer);
fos.flush();
fos.close();
Run Code Online (Sandbox Code Playgroud)
但这是一个例外:
java.io.FileNotFoundException:/mnt/sdcard/MyApp/MediaCard/MediaCard-0.png(没有这样的文件或目录)
在那条线上: fos = new FileOutputStream(file);
如果我将文件名设置为:"MyApp/MediaTag-"+objectId+"它正在工作,但如果我尝试创建并将文件保存到另一个目录,则会抛出异常.那么任何想法我做错了什么?
还有一个问题:有没有办法让我的文件在外部存储中保密,这样用户就无法在图库中看到它们,只有当他连接他的设备时Disk Drive?
python ×5
android ×3
argparse ×1
build ×1
compilation ×1
eclipse ×1
external ×1
file ×1
file-upload ×1
geolocation ×1
list ×1
popen ×1
pycharm ×1
servlet-3.0 ×1
servlets ×1
set ×1
storage ×1
subprocess ×1
tomcat ×1
type-hinting ×1