为什么Location.getAltitude总是返回为零,至少在ios模拟器返回桌面

I'm trying to draw custom UI (a path in this case) on top of a Gallery. I've extended the base Gallery class and overwritten the draw method like this:
public class MyGallery extends Gallery {
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawPath(mPath, mPaint);
I thought that putting my path drawing after super.onDraw would make sure that the path was drawn on top of the gallery AND it's child views, but instead the child views are layered on top of my path.
Does anyone know how to draw this properly?
(I know I could include a RelativeLayout and layer a further view to draw my path on top of the Gallery that way, but I'd rather keep it all in one class)
解决方案 I found this straight after asking, so decided to post anyway in case someone has the same issue. To draw over child views in a Gallery, overwrite dispatchDraw instead of onDraw
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
canvas.drawPath(mPath,mPaint);
本文地址: &
我试图在画廊的上面画自定义用户界面(在这种情况下路径)。我已经扩展底座画廊类,并覆盖Draw方法是这样的: 公共类MyGallery扩展库{...@覆盖保护无效的onDraw(帆布油画){
super.onDraw(画布);
canvas.drawPath(的mpath,mPaint);} 我觉得把我的画路径后 super.onDraw 将确保该路径被画在画廊之上,这是孩子的意见,而是孩子的意见是分层的,我的道路上。有谁知道如何正确地得出这样的?(我知道我可以包括的RelativeLayout和层次进一步视图中绘制的画廊这样的顶我的道路,但我宁愿这一切保持在一个类)解决方案 我发现这个要求后直,所以决定的情况下,反正有人张贴了同样的问题。为了笼络子视图在一个画廊,覆盖 dispatchDraw 而不是的onDraw
@覆盖保护无效dispatchDraw(帆布油画){
super.dispatchDraw(画布);
canvas.drawPath(的mpath,mPaint);}
本文地址: &
扫一扫关注官方微信android获取GPS经纬度,全是按照书下的代码,但是编译没有有关问题,在模拟器下运行异常,大神啊_6C社区
android获取GPS经纬度,全是按照书下的代码,但是编译没有有关问题,在模拟器下运行异常,大神啊
android获取GPS经纬度,全是按照书下的代码,但是编译没有有关问题,在模拟器下运行异常,大神啊
android获取GPS经纬度,全是按照书上的代码,但是编译没有问题,在模拟器上运行错误,大神求助啊……这是源代码package walk.a;import android.app.Aimport android.os.Bimport android.app.Aimport android.os.B//package org.crazyit.import android.app.Aimport android.content.Cimport android.location.Limport android.location.LocationLimport android.location.LocationMimport android.os.Bimport android.widget.EditTpublic class WalkActivity extends Activity{// 定义LocationManager对象LocationManager locM// 定义程序界面中的EditText组件EditTpublic void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);// 获取程序界面上的EditText组件show = (EditText) findViewById(R.id.show);// 创建LocationManager对象locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // 从GPS获取最近的最近的定位信息Location location = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);// 使用location根据EditText的显示updateView(location);// 设置每3秒获取一次GPS的定位信息locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER , 3000, 8, new LocationListener(){@Overridepublic void onLocationChanged(Location location){// 当GPS定位信息发生改变时,更新位置updateView(location);}@Overridepublic void onProviderDisabled(String provider){updateView(null);}@Overridepublic void onProviderEnabled(String provider){// 当GPS LocationProvider可用时,更新位置updateView(locManager.getLastKnownLocation(provider));}@Overridepublic void onStatusChanged(String provider, int status,Bundle extras){}}); }// 更新EditText中显示的内容public void updateView(Location newLocation){if (newLocation != null){StringBuilder sb = new StringBuilder();sb.append("实时的位置信息:n");sb.append("经度:");sb.append(newLocation.getLongitude());sb.append("n纬度:");sb.append(newLocation.getLatitude());sb.append("n高度:");sb.append(newLocation.getAltitude());sb.append("n速度:");sb.append(newLocation.getSpeed());sb.append("n方向:");sb.append(newLocation.getBearing());show.setText(sb.toString());}else{ // 如果传入的Location对象为空则清空EditTextshow.setText("");}}}一点都没有改动,只是改了改类的名字,但是运行的时候,就是会报错,模拟器说意外停止,请重试。真心不知道到底哪里有错误……求大神……------解决方案--------------------探讨引用:没发LOG,不知道哪知错了。应该需要在manifest.xml里增加权限,这个需要联网的吧。我加了一个别的没加,不知道是不是这个的原因------解决方案--------------------缺少权限
都放进去试下------解决方案--------------------探讨缺少权限
本文地址: /article-.shtml 欢迎转载Does anybody know why my getAltitude in the following always returns 0?
package com.example.
import android.app.A
import android.content.C
import android.database.sqlite.SQLiteD
import android.location.L
import android.location.LocationL
import android.location.LocationM
import android.os.B
import android.util.L
public class HelloAndroid extends Activity {
public void onCreate(Bundle savedInstanceState) {
Log.d("main", "onCreate");
setupGps();
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LocationListener locationL
void setupGps() {
Log.d("gps", "Setting up GPS...");
locationListener = new MyLocationListener();
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 20000, 5,
locationListener);
Log.d("gps",
"GPS supports altitude: "
+ lm.getProvider(LocationManager.GPS_PROVIDER)
.supportsAltitude());
Log.d("gps", "Finished setting up GPS.");
static class MyLocationListener implements LocationListener {
public void onLocationChanged(Location location) {
Log.d("gps", "onLocationChanged");
Log.d("gps",
"x: " + location.getLongitude() + ", y: "
+ location.getLatitude() + ", alt.: "
+ location.getAltitude());
public void onProviderDisabled(String provider) {
Log.d("gps", "onProviderDisabled");
public void onProviderEnabled(String provider) {
Log.d("gps", "onProviderEnabled");
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.d("gps",
"onStatusC new status: " + String.valueOf(status));
To test, I issue a geo command with an altitude to the emulator:
[someone@somewhere ~]$ telnet localhost 5554
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Android Console: type 'help' for a list of commands
geo fix -121.19 4392
But getAltitude() returns 0:
I have only tried with emulated devices.
Following up on cheeken's comment, I verified that Location.hasAltitude() is true. It is. Any other idea?
public void onLocationChanged(Location location) {
Log.d("gps", "onLocationChanged");
Log.d("gps", "x: " + location.getLongitude()
+ ", y: " + location.getLatitude());
Log.d("gps", "hasAltitude: " + location.hasAltitude()
+ ", alt.: " + location.getAltitude());
解决方案 It seems like a lot of people are having similar issues with this and has even been reported as a . I wouldn't be surprised if the emulator simply doesn't support it at this time. You'll probably have to work with a real device.
本文地址: &
有谁知道为什么我在下面getAltitude总是返回0? 包com.example.进口android.app.A进口android.content.C进口android.database.sqlite.SQLiteD进口android.location.L进口android.location.LocationL进口android.location.LocationM进口android.os.B进口android.util.L公共类HelloAndroid延伸活动{
公共无效的onCreate(捆绑savedInstanceState){
Log.d(“主”,“的onCreate”);
setupGps();
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
LocationListener的LocationListener的;
LM的LocationM
无效setupGps(){
Log.d(“GPS”,“设置GPS ...”);
LocationListener的=新MyLocationListener();
LM =(的LocationManager)getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,20000,5,
LocationListener的);
Log.d(“GPS”,
“GPS支持海拔高度:”
+ lm.getProvider(LocationManager.GPS_PROVIDER)
.supportsAltitude());
Log.d(“GPS”,“完成设置GPS”);
静态类MyLocationListener实现LocationListener的{
公共无效onLocationChanged(地点){
Log.d(“全球定位系统”,“onLocationChanged”);
Log.d(“GPS”,
“×:”+ location.getLongitude(+)“,Y:”
+ location.getLatitude()+“,ALT:”
+ location.getAltitude());
公共无效onProviderDisabled(字符串提供商){
Log.d(“全球定位系统”,“onProviderDisabled”);
公共无效onProviderEnabled(字符串提供商){
Log.d(“全球定位系统”,“onProviderEnabled”);
公共无效onStatusChanged(字符串提供商,INT地位,捆绑演员){
Log.d(“GPS”,
“onStatusC新的状态:”+将String.valueOf(状态));
}} 要测试,我发出了高度和仿真地理命令:
[某人@某处?] $远程登录本地主机5554尝试127.0.0.1 ...连接到本地主机。转义字符是'^]'。Android的控制台:键入“help”以命令的列表好地理修复-121.19 4392好 但 getAltitude()返回0:
我只试过与模拟的设备。 修改 在cheeken的评论之后,我验证了 Location.hasAltitude()是真实的。它是。任何其他的想法? 公共无效onLocationChanged(地点){
Log.d(“全球定位系统”,“onLocationChanged”);
Log.d(“全球定位系统”,“X:”+ location.getLongitude()
+“,Y:”+ location.getLatitude());
Log.d(“全球定位系统”,“hasAltitude:”+ location.hasAltitude()
+“,中高音.:”+ location.getAltitude());}
解决方案 这似乎是一个很多人都具有这种类似的问题,甚至被报告为的。我也不会感到惊讶,如果模拟器根本没有在这个时候支持它。你可能有一个真正的设备上运行。
本文地址: &
扫一扫关注官方微信}

我要回帖

更多关于 模拟器返回桌面 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信