Android 地理位置接口始终返回403:未配置访问
我已经输入了我的信用卡信息并购买了“谷歌地图API v2”、“谷歌地图API v3”和“谷歌地图地理定位API”。我确信我的API_密钥是正确的。但当我的android应用程序查询地理位置服务器时,服务器每次都返回403(访问未配置) 我的项目编号是663182082293,项目ID是trustgo.com:trustgo。非常感谢您的帮助。提前谢谢 电邮:shien01@baidu.com 以下是我的请求代码:Android 地理位置接口始终返回403:未配置访问,android,google-maps,geolocation,Android,Google Maps,Geolocation,我已经输入了我的信用卡信息并购买了“谷歌地图API v2”、“谷歌地图API v3”和“谷歌地图地理定位API”。我确信我的API_密钥是正确的。但当我的android应用程序查询地理位置服务器时,服务器每次都返回403(访问未配置) 我的项目编号是663182082293,项目ID是trustgo.com:trustgo。非常感谢您的帮助。提前谢谢 电邮:shien01@baidu.com 以下是我的请求代码: HttpClient client = new DefaultHttpClient
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(
"https://www.googleapis.com/geolocation/v1/geolocate?key=AIzaSyChtmYL9zXe0XNhZQeThF8A9t_YpQ-E1p8");
try {
JSONObject holder = new JSONObject();
holder.put("homeMobileCountryCode", cell.MCC);
holder.put("homeMobileNetworkCode", cell.MNC);
holder.put("radioType", "gsm");
holder.put("carrier", "samsung");
JSONObject cellTower = new JSONObject();
cellTower.put("cellId", cell.CID);
cellTower.put("locationAreaCode", cell.LAC);
cellTower.put("mobileCountryCode", cell.MCC);
cellTower.put("mobileNetworkCode", cell.MNC);
cellTower.put("age", 0);
cellTower.put("signalStrength", -60);
cellTower.put("timingAdvance", 15);
JSONArray cellTowerarray = new JSONArray();
cellTowerarray.put(cellTower);
holder.put("cellTowers", cellTowerarray);
JSONObject wifiTower = new JSONObject();
WifiManager wm = (WifiManager) MainActivity.this
.getApplicationContext().getSystemService(
Context.WIFI_SERVICE);
wm.getDhcpInfo();
List<WifiConfiguration> list = wm.getConfiguredNetworks();
WifiConfiguration wif;
WifiInfo wifiInfo = wm.getConnectionInfo();
List<ScanResult> results = wm.getScanResults();
if (results != null && results.size() > 0) {
JSONArray wifiTowerarray = new JSONArray();
String wifimac = wifiInfo.getMacAddress();
int strength = wifiInfo.getRssi();
wifiTower.put("macAddress", wifimac);
wifiTower.put("signalStrength", strength);
wifiTower.put("age", 0);
wifiTower.put("channel", 2417);
wifiTower.put("signalToNoiseRatio", -85);
wifiTowerarray.put(wifiTower);
holder.put("wifiAccessPoints", wifiTowerarray);
}
StringEntity query = new StringEntity(holder.toString());
query.setContentType("application/json");
post.setEntity(query);
HttpResponse response = client.execute(post);
HttpEntity entity = response.getEntity();
BufferedReader buffReader = new BufferedReader(
new InputStreamReader(entity.getContent()));
StringBuffer strBuff = new StringBuffer();
String result = null;
while ((result = buffReader.readLine()) != null) {
strBuff.append(result);
}
JSONObject json = new JSONObject(strBuff.toString());
String str1 = json.getString("location");
JSONObject subjosn = new JSONObject(str1);
itude.latitude = subjosn.getString("latitude");
itude.longitude = subjosn.getString("longitude");
} catch (Exception e) {
Log.e(e.getMessage(), e.toString());
} finally {
post.abort();
client = null;
}
HttpClient=newdefaulthttpclient();
HttpPost=新的HttpPost(
"https://www.googleapis.com/geolocation/v1/geolocate?key=AIzaSyChtmYL9zXe0XNhZQeThF8A9t_YpQ-E1p8”);
试一试{
JSONObject holder=新的JSONObject();
holder.put(“HomeMobileContrycode”,cell.MCC);
holder.put(“homeMobileNetworkCode”,cell.MNC);
持票人。看跌期权(“无线电类型”、“gsm”);
持有人。看跌期权(“开利”、“三星”);
JSONObject cellTower=新的JSONObject();
cellTower.put(“cellId”,cell.CID);
cellTower.put(“位置区域代码”,cell.LAC);
cellTower.put(“移动国家代码”,cell.MCC);
cellTower.put(“mobileNetworkCode”,cell.MNC);
cellTower.put(“年龄”,0);
cellTower.put(“信号强度”,-60);
cellTower.put(“timingAdvance”,15);
JSONArray cellTowerarray=新的JSONArray();
牢房塔放射线(牢房塔);
持牌人。看跌期权(“cellTowers”,cellTowerarray);
JSONObject wifiTower=新的JSONObject();
WifiManager wm=(WifiManager)MainActivity.this
.getApplicationContext().getSystemService(
无线上网服务);
wm.getDhcpInfo();
List List=wm.getConfiguredNetworks();
wific配置wif;
WifiInfo WifiInfo=wm.getConnectionInfo();
List results=wm.getScanResults();
if(results!=null&&results.size()>0){
JSONArray wifiTowerarray=新的JSONArray();
字符串wifimac=wifiInfo.getMacAddress();
int-strength=wifiInfo.getRssi();
wifiTower.put(“macAddress”,wifimac);
wifiTower.put(“信号强度”,强度);
wifiTower.put(“年龄”,0);
wifiTower.put(“频道”,2417);
wifiTower.put(“信号音调噪声”,-85);
wifiTowerarray.put(wifiTower);
持证人看跌期权(“wifiAccessPoints”,wifiTowerarray);
}
StringEntity查询=新的StringEntity(holder.toString());
setContentType(“应用程序/json”);
post.setEntity(查询);
HttpResponse response=client.execute(post);
HttpEntity=response.getEntity();
BufferedReader buffReader=新的BufferedReader(
新的InputStreamReader(entity.getContent());
StringBuffer strBuff=新的StringBuffer();
字符串结果=null;
而((result=buffReader.readLine())!=null){
strBuff.append(结果);
}
JSONObject json=新的JSONObject(strBuff.toString());
String str1=json.getString(“位置”);
JSONObject subject n=新的JSONObject(str1);
纬度=subgosn.getString(“纬度”);
vitence.longide=subgosn.getString(“经度”);
}捕获(例外e){
Log.e(e.getMessage(),e.toString());
}最后{
post.abort();
client=null;
}
您是否已从Google Play API控制台激活您的Google Play服务活动??如果没有,请检查一下,进入谷歌API控制台->使用Gmail登录->在控制台左上角点击服务->你会在那里看到很多谷歌服务->选择谷歌地图Android API v2和谷歌地图API v2和谷歌地图API v3以及任何其他你需要的服务 对。我以前启动过这三项服务。我还用谷歌搜索了这一期,看看以前是否有人遇到过同样的问题。但令人失望的是,以前几乎没有相同的问题。谢谢。在我删除了SHA1证书指纹和包名的限制后,API工作了。