I am trying to simulate motion of the emulator device in the ddms perspective. I am using a gpx file which contains elevation elements, but when my code runs, it only retrieves lat/lon and says that elevation = 0.
My questi开发者_Go百科on is, Can the android emulator be used to simulate altitude, speed etc, or is it just for latitude and longitude data?
This is not really an answer, however it may give you some useful ideas.
What type of provider do you use? There are 2 options: LocationManager.GPS_PROVIDER
and LocationManager.NETWORK_PROVIDER
. My guess is that altitude can only be available if LocationManager.GPS_PROVIDER
is used.
Also on you Location
updates (in LocationListener.onLocationChanged(Location location)
) you can call location.hasAltitude()
. It returns true if this fix contains altitude information, false otherwise.
UPDATE:
So it looks like you are experiencing some emulator issue. I rerember I was on Eclipse 3.4.1 + ADT 0.9.5 + Android 2.0.1 app + WinXP and the only way to feed the emulator with GPS fixes was to use Telnet. So I just created a helper Ruby script for that:
require 'net/telnet'
scenario = [
'sleep 1',
'geo fix -121.45356 46.51119 0',
'sleep 3',
'geo fix -80.45356 45.51119 0'
]
simulator_connection = nil
begin
simulator_connection =
Net::Telnet::new(
'Timeout' => 5,
'Port' => 5554,
'Prompt' => /(OK|\AKO.*\z)/
)
rescue Errno::EBADF
puts '> Error: running Android Emulator not found. Exiting ...'
exit
end
puts '> got connection to Android Emulator'
begin
scenario.each do |action|
if action =~ /\Asleep\s\d+\z/
puts "> #{action} secs ..."
eval(action)
else
puts "> execute \"#{action}\""
simulator_connection.cmd(action)
end
end
puts '> job is done, exiting ...'
ensure
simulator_connection.close
end
You see I pass 0 as the altitude (the last param at 'geo fix ...'), however you may try with your non-zero values. If you are not familiar with Ruby, then you could probably adopt the script to your favorite scripting language. Let me know if this worked for you.
精彩评论