लौटाता है मैं अपने एंड्रॉइड ऐप के लिए एक सुविधा को लागू करने की कोशिश कर रहा हूं जो डिवाइस की यात्रा की गति और दिशा प्राप्त करता है, इससे कोई फर्क नहीं पड़ता कि डिवाइस कहां पर है। उदाहरण के लिए: यदि मेरा एंड्रॉइड डिवाइस उत्तर दिशा में इंगित किया गया है और यदि मैं दक्षिण दिशा में पीछे की ओर बढ़ रहा हूं, तो यह वापस आ जाएगा कि मैं दक्षिण की ओर बढ़ रहा हूं।एंड्रॉइड स्थान getBearing() हमेशा 0
मैं चारों ओर देख रहा हूं और मैं स्थान की getBearing() विधि का उपयोग करने की संभावना के साथ आया हूं (फिर भी, मुझे नहीं पता कि इससे मेरी पूरी समस्या हल हो जाएगी)। जब मैं getBearing() का आह्वान करता हूं, तो यह हमेशा किसी कारण से 0.0 लौटाता है। मुझे कोई जानकारी नहीं है की क्यों। यहां मेरा कोड है:
LocationManager lm;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gcm);
setUpUI(findViewById(R.id.LinearLayout1));
isRegged = false;
// GCM startup
gcm = GoogleCloudMessaging.getInstance(this);
context = getApplicationContext();
gps = new GPSTracker(context);
// gps.startListening(context);
// gps.setGpsCall(this);
/*
* Variables to indicate location and device ID
*/
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (gps.getIsGPSTrackingEnabled())
{
longitude = Double.valueOf(gps.getLongitude()).toString();
latitude = Double.valueOf(gps.getLatitude()).toString();
}
deviceID = telephonyManager.getDeviceId();
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, (float) 0.0,
this);
}
यह वह जगह है जहां मुझे असर मिल रहा है।
@Override
public void onLocationChanged(Location currentLocation)
{
float speed = 0;
float speed_mph = 0;
if (previousLocation != null)
{
float distance = currentLocation.distanceTo(previousLocation);
// time taken (in seconds)
float timeTaken = ((currentLocation.getTime() - previousLocation
.getTime())/1000);
// calculate speed
if (timeTaken > 0)
{
speed = getAverageSpeed(distance, timeTaken);
speed_mph = (float) (getAverageSpeed(distance, timeTaken)/1.6);
}
if (speed >= 0)
{
info_text.setVisibility(View.VISIBLE);
info_text_mph.setVisibility(View.VISIBLE);
DecimalFormat df = new DecimalFormat("#.#");
info_text.setText("Speed: " + df.format(speed) + " " + "km/h");
info_text_mph.setText(" Speed: " + df.format(speed_mph) + " "
+ "mph");
if (speed >= 10 && lm.getProvider(LocationManager.GPS_PROVIDER).supportsBearing())
{
float degree = currentLocation.getBearing();
direction_text.setVisibility(View.VISIBLE);
Log.i(TAG, String.valueOf(degree));
if (degree == 0 && degree < 45 || degree >= 315
&& degree == 360)
{
direction_text.setText("You are: Northbound");
}
if (degree >= 45 && degree < 90)
{
direction_text.setText("You are: NorthEastbound");
}
if (degree >= 90 && degree < 135)
{
direction_text.setText("You are: Eastbound");
}
if (degree >= 135 && degree < 180)
{
direction_text.setText("You are: SouthEastbound");
}
if (degree >= 180 && degree < 225)
{
direction_text.setText("You are: SouthWestbound");
}
if (degree >= 225 && degree < 270)
{
direction_text.setText("You are: Westbound");
}
if (degree >= 270 && degree < 315)
{
direction_text.setText("You are: NorthWestbound");
}
}
}
}
previousLocation = currentLocation;
}
बहुत बहुत धन्यवाद!
आपकी प्रतिक्रिया के लिए धन्यवाद और मैं क्षमा चाहता हूं कि मैं पूरी तरह से अपने पोस्ट में उल्लेख करना भूल गया कि मैं जीपीएस प्रदाता का उपयोग कर रहा हूं। मैं अपना कोड अपडेट करूंगा। – user3171597
और क्या आपने बाहर होने और लंबी इमारतों या अन्य वस्तुओं से दूर किसी स्थान पर getBearing() के उपयोग का प्रयास किया जो आपको उपग्रह संचार से रोक सकता है? –
हां मैंने किया। मैंने चारों ओर गाड़ी चलाते समय उस सुविधा का परीक्षण करने की कोशिश की है। यद्यपि गति बहुत सटीक है (5-10 किमी दूर) getBearing() हमेशा 0 देता है, जो हमेशा "आप हैं: नॉर्थबाउंड" लौटाता है इससे कोई फर्क नहीं पड़ता कि मैं किस दिशा में जाता हूं। – user3171597