我输入了我的信用卡信息并购买了“Google Maps API v2”、“Google Maps API v3”和“Google Maps Geolocation API”。我确信我的 API_key 是正确的。但是当我的 android 应用程序查询地理位置服务器时,服务器每次都返回 403(访问未配置)。
我的项目号是663182082293,项目ID是trustgo.com:trustgo。任何帮助深表感谢。提前致谢!
邮箱:shien01@baidu.com
以下是我的请求代码:
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;
}