I try to get address from android.location.Geocode. Below is the code:
// Grant whatever permission I think is related
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_WIFI_STATE,
Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.VIBRATE,
Manifest.permission.INTERNET},100);
// Request Geocode service. Function: provide an address to addressStr. Expected output: address related information, e.g. latitude, longtitude
import android.location.Geocoder; ...
String addressStr = "#3140-4000 No.3 Rd, Richmond, BC Canada";
Geocoder coder = new Geocoder(mContext);
List<Address> address;
address = coder.getFromLocationName(addressStr, 1);
System.out.println(address.size());
//Output in mobile device: 0
Result:
- Run on a Android device - the address.size() always 0 (PROBLEM here!)
- Run on a Android emulator - result normal
coder.isPresent() always return true in above situation.
As the same piece of code working fine in emulator. And it worked in pass few days when I first created this app. I guess google provide free service to emulator, and a certain free quota to actual device. Once the free quota used up, it won't work in actual device anymore. But still work in emulator
Any comment on my guessing?