Skip to content

Commit bb21cf9

Browse files
committed
API now functions correctly in the App Engine environment.
1 parent f98913a commit bb21cf9

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/main/java/com/google/maps/GaeRequestHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.google.maps;
1717

1818
import com.google.appengine.api.urlfetch.FetchOptions;
19+
import com.google.appengine.api.urlfetch.HTTPHeader;
1920
import com.google.appengine.api.urlfetch.HTTPMethod;
2021
import com.google.appengine.api.urlfetch.HTTPRequest;
2122
import com.google.appengine.api.urlfetch.URLFetchService;
@@ -60,6 +61,7 @@ public <T, R extends ApiResponse<T>> PendingResult<T> handlePost(String hostName
6061
HTTPRequest req = null;
6162
try {
6263
req = new HTTPRequest(new URL(hostName + url), HTTPMethod.POST, fetchOptions);
64+
req.setHeader(new HTTPHeader("Content-Type", "application/json; charset=utf-8"));
6365
req.setPayload(payload.getBytes());
6466
} catch (MalformedURLException e) {
6567
LOG.log(Level.SEVERE, String.format("Request: %s%s", hostName, url), e);

src/main/java/com/google/maps/internal/GaePendingResult.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.google.gson.Gson;
2424
import com.google.gson.GsonBuilder;
2525
import com.google.gson.JsonSyntaxException;
26+
import com.google.maps.GeolocationApi;
2627
import com.google.maps.PendingResult;
2728
import com.google.maps.PhotoRequest;
2829
import com.google.maps.errors.ApiException;
@@ -167,6 +168,7 @@ private T parseResponse(GaePendingResult<T, R> request, HTTPResponse response) t
167168
.registerTypeAdapter(PriceLevel.class, new PriceLevelAdaptor())
168169
.registerTypeAdapter(Instant.class, new InstantAdapter())
169170
.registerTypeAdapter(LocalTime.class, new LocalTimeAdapter())
171+
.registerTypeAdapter(GeolocationApi.Response.class, new GeolocationResponseAdapter())
170172
.setFieldNamingPolicy(fieldNamingPolicy)
171173
.create();
172174

src/test/java/com/google/maps/GeolocationApiTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,29 @@ public void testMinimumWifiGeolocation() throws Exception {
101101
assertEquals("lng", -122.0585196, result.location.lng, 0.00001);
102102
}
103103
@Test
104+
public void testBasicGeolocation() throws Exception {
105+
GeolocationResult result = GeolocationApi.newRequest(context)
106+
.ConsiderIp(false)
107+
.AddWifiAccessPoint(new WifiAccessPoint.WifiAccessPointBuilder()
108+
.MacAddress("92:68:c3:f8:76:47")
109+
.SignalStrength(-42)
110+
.SignalToNoiseRatio(68)
111+
.createWifiAccessPoint())
112+
.AddWifiAccessPoint(new WifiAccessPoint.WifiAccessPointBuilder()
113+
.MacAddress("94:b4:0f:ff:6b:11")
114+
.SignalStrength(-55)
115+
.SignalToNoiseRatio(55)
116+
.createWifiAccessPoint())
117+
.CreatePayload()
118+
.await();
119+
120+
assertNotNull(result);
121+
assertNotNull(result.location);
122+
assertEquals("accuracy", 150.0, result.accuracy, 0.00001);
123+
assertEquals("lat", 37.3989885, result.location.lat, 0.00001);
124+
assertEquals("lng", -122.0585196, result.location.lng, 0.00001);
125+
}
126+
@Test
104127
public void testAlternateWifiSetterGeolocation() throws Exception {
105128
WifiAccessPoint[] wifiAccessPoints = new WifiAccessPoint[2];
106129
wifiAccessPoints[0] = new WifiAccessPoint.WifiAccessPointBuilder()

0 commit comments

Comments
 (0)