Android模拟器,发现模拟用户的位置坐标。有问题 [英] Android emulator, Finding mock user location coordinates. Having problems

查看:271
本文介绍了Android模拟器,发现模拟用户的位置坐标。有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有麻烦试图找到用户的经度和位置,我跑我的程序和设置地理修复telnet命令为模拟位置。当模拟器运行时,我设置了模拟坐标只为仿真器变得反应迟钝,并有我的程序无法检测输入坐标。

 进口android.app.Activity;
进口android.content.Context;
进口android.location.Location;
进口android.location.LocationListener;
进口android.location.LocationManager;
进口android.location.LocationProvider;
进口android.os.Bundle;
进口android.widget.TextView;
进口android.widget.Toast;

公共类LBSact延伸活动{
    / **第一次创建活动时调用。 * /
    公共双经度;
    公众双重纬度;
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);
        经度= 0;
        纬度= 0;
        //创建侦听器和经理
        LocationManager LManager =(LocationManager)this.getSystemService(Context.LOCATION_SERVICE);

        LocationListener的createListen =新LocationListener的(){
            @覆盖
            公共无效onLocationChanged(位置定位){
                //经度= location.getLongitude();
                //纬度= location.getLatitude();
                字符串printout1 =我现在的位置是:+纵横=+ location.getLatitude()+
                经度=+ location.getLongitude();
                    Toast.makeText(getApplicationContext(),printout1,Toast.LENGTH_LONG).show();

            }
            @覆盖
            公共无效onProviderDisabled(字符串提供商){
                Toast.makeText(getApplicationContext(),GPS已禁用,Toast.LENGTH_LONG).show();

            }
            @覆盖
            公共无效onProviderEnabled(字符串提供商){
                Toast.makeText(getApplicationContext(),GPS功能的,Toast.LENGTH_LONG).show();

            }
            @覆盖
            公共无效onStatusChanged(字符串商,INT地位,
                    捆绑演员){
            }
        };

        //不能使用网络的仿真器,只能用GPS模拟地点
        //Toast.makeText(getApplicationContext()?这是否工作,Toast.LENGTH_LONG).show();
        LManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,createListen);
    }

}
 

解决方案

首先。我假设你已经阅读以下内容: 的http://developer.android.com/guide/topics/location/obtaining-user-location.html

既然你提到注入模拟位置数据。有一对夫妇的其他东西,你可以尝试,比如你可以使用一个KML文件注入GPS位置: 的http://developer.android.com/guide/developing/tools/ddms.html#emulator-control

但是,你应该做的主要事情就是创建日志信息,让您可以更准确地检测,你的计划是失败的。下面是关于如何设置logcat的一篇文章: http://www.droidnova.com/debugging-in-android - 使用月食,541.html

我会建议这是发送文本到屏幕上可能并不总是工作作为您的应用程序可能会崩溃,然后才会慢慢者来电。

另外,你有没有试图通过Eclipse中调试应用程序?这将打破上的崩溃,给你在哪里应用程序发生故障的位置。

为您提供更多的细节上的问题,我会更新这个答案,因为它是一种很难看到发生了什么没有一个堆栈跟踪或登录痕迹。

Hey guys, I'm having trouble trying to find the user's longitude and location as I run my program and set the telnet command for geo fix for the mock location. While the emulator is running, I set the mock coordinates only for the emulator to become unresponsive and have my program fail in detecting the input coordinates.

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 listener and manager
        LocationManager LManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

        LocationListener createListen = new LocationListener(){
            @Override
            public void onLocationChanged(Location location) {
                //longitude = location.getLongitude();
                //latitude = location.getLatitude();
                String printout1 = "My current location is: " + "Latitude = " + location.getLatitude() +
                "Longitude = " + location.getLongitude();
                    Toast.makeText(getApplicationContext(),printout1,Toast.LENGTH_LONG).show();

            }
            @Override
            public void onProviderDisabled(String provider) {
                Toast.makeText(getApplicationContext(), "GPS disabled", Toast.LENGTH_LONG).show();

            }
            @Override
            public void onProviderEnabled(String provider) {
                Toast.makeText(getApplicationContext(), "GPS enabled", Toast.LENGTH_LONG).show();

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

        //Cant use Network with emulator, can only use GPS mock locations
        //Toast.makeText(getApplicationContext(), "Does this work?", Toast.LENGTH_LONG).show();
        LManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, createListen);
    }

}

解决方案

First of all. I'm assuming you have read the following: http://developer.android.com/guide/topics/location/obtaining-user-location.html

Since you mentioned injecting mock location data. There are a couple other things you could try to, for instance you could use a KML file to inject GPS locations: http://developer.android.com/guide/developing/tools/ddms.html#emulator-control

But the main thing you should do is create logging messages so that you can more accurately detect where your program is failing. Here's an article on how to setup logcat: http://www.droidnova.com/debugging-in-android-using-eclipse,541.html

I would suggest this as sending text to the screen might not always work as your application can crash before it gets to those calls.

Also, have you tried debugging your application through Eclipse? It will break on the crash and give you the location of where the app is failing.

I'll update this answer as you give more details on the issue as it's kind of hard to see what's happening without a stack trace or logging trace.

这篇关于Android模拟器,发现模拟用户的位置坐标。有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆