android.location.Location setters not working as expected

余生长醉 提交于 2019-12-22 18:08:08

问题


I need to create a Location object from some latitude and longitude values, without going through a location provider. I do the following:

Location l = new Location("");
l.setLatitude(32);
l.setLongitude(43);

The values, however, are not set properly, since both getLatitude() and getLongitude() return 0.

Can you please tell me where is the problem? Isn't this the correct way to create a "custom" Location?


回答1:


I figured it out eventually. When unit testing using the Android APIs, you need to use the instrumentation framework. I was using JUnit alone, thus the malfunctioning. I resolved by using Roboelectric, a tool that sort of emulates the Android platform allowing you to run unit tests that use Android APIs without bringing up a device emulator every time.



来源:https://stackoverflow.com/questions/30692807/android-location-location-setters-not-working-as-expected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!