Google Maps Elevation Api Wrong Value

I tried this method to get the height using longitude and latitude

private double lookingForAltitude(double latitude, double longitude) { double result = Double.NaN; HttpClient httpClient = new DefaultHttpClient(); HttpContext localContext = new BasicHttpContext(); String url = "http://maps.googleapis.com/maps/api/elevation/" + "xml?locations=" + String.valueOf(longitude) + "," + String.valueOf(latitude) + "&sensor=true"; HttpGet httpGet = new HttpGet(url); try { HttpResponse response = httpClient.execute(httpGet, localContext); HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); int r = -1; while ((r = instream.read()) != -1) respStr.append((char) r); String tagOpen = "<elevation>"; String tagClose = "</elevation>"; if (respStr.indexOf(tagOpen) != -1) { int start = respStr.indexOf(tagOpen) + tagOpen.length(); int end = respStr.indexOf(tagClose); String value = respStr.substring(start, end); result = (double)(Double.parseDouble(value)); } instream.close(); } } catch (ClientProtocolException e) {} catch (IOException e) {} return result; } 

Unfortunately not working

Walkthrough for example

 double latitude = 48.856908 double longitude = 2.352426 

Rue de Tivoli Paris France

get -3997.6191406

What's wrong?

I am mistaken in other places.

PS

I heard that the request limit for this function is 2500. Is this associated with each IP address or is the maximum amount for all applications using my certificate?

+4
source share
1 answer

You change the values ​​for latitude and longitude.

http://maps.googleapis.com/maps/api/elevation/xml?locations=2.352426,48.856908&sensor=true returns:

 <result> <location> <lat>2.3524260</lat> <lng>48.8569080</lng> </location> <elevation>-3997.6191406</elevation> <resolution>610.8129272</resolution> </result> 

So far, http://maps.googleapis.com/maps/api/elevation/xml?locations=48.856908,2.352426&sensor=true returns:

 <result> <location> <lat>48.8569080</lat> <lng>2.3524260</lng> </location> <elevation>32.0345688</elevation> <resolution>9.5439520</resolution> </result> 

You must call lookingForAltitude with the changed values.

+4
source

Source: https://habr.com/ru/post/1441382/


All Articles