Package org.wicketstuff.gmap.geocoder
Class Geocoder
- java.lang.Object
-
- org.wicketstuff.gmap.geocoder.Geocoder
-
- All Implemented Interfaces:
Serializable
public class Geocoder extends Object implements Serializable
Geocoder. See: https://developers.google.com/maps/documentation/geocoding/- Author:
- Thijs Vonk, Dieter Tremel
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
OUTPUT_JSON
static String
OUTPUT_XML
-
Constructor Summary
Constructors Constructor Description Geocoder(com.fasterxml.jackson.databind.ObjectMapper mapper, String apiKey)
Configuration Constructor.
If you have to customize the defaultObjectMapper
Geocoder(String apiKey)
Default Constructor.
Create anObjectMapper
.
TheObjectMapper
ignores unknown properties when mapping from JSON to POJO.
UseGeocoder(com.fasterxml.jackson.databind.ObjectMapper, java.lang.String)
to customize
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
centerAndFitZoomForAdress(GMap map, String address)
Convenience method to center and fit the zoom for an address, on the given map.GLatLng
decode(String response)
Decode an response of an geocoder request to POJOs.
Following the successful mapping from JSON to POJO
all hits are available ingeocoderResult
String
encode(String address)
builds the google geo-coding urlGLatLng
geocode(String address)
Invoke a geocoder request to the GoogleMaps API.
Only return the first element ofgeocoderResult
to be backward compatible.
After successful call ofgeocode(String)
you can get all results fromgeocoderResult
GeocoderResult
getGecoderResult()
Get the Result of the last geocoder Requestprotected InputStream
invokeService(String address)
fetches the url content
-
-
-
Field Detail
-
OUTPUT_XML
public static final String OUTPUT_XML
- See Also:
- Constant Field Values
-
OUTPUT_JSON
public static final String OUTPUT_JSON
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Geocoder
public Geocoder(String apiKey)
Default Constructor.
Create anObjectMapper
.
TheObjectMapper
ignores unknown properties when mapping from JSON to POJO.
UseGeocoder(com.fasterxml.jackson.databind.ObjectMapper, java.lang.String)
to customize- Parameters:
apiKey
- your Google Maps API-key
-
Geocoder
public Geocoder(com.fasterxml.jackson.databind.ObjectMapper mapper, String apiKey)
Configuration Constructor.
If you have to customize the defaultObjectMapper
- Parameters:
mapper
- your customized ObjectMapperapiKey
- your Google Maps API-key- See Also:
Geocoder#Geocoder()
-
-
Method Detail
-
decode
public GLatLng decode(String response) throws GeocoderException, com.github.openjson.JSONException
Decode an response of an geocoder request to POJOs.
Following the successful mapping from JSON to POJO
all hits are available ingeocoderResult
- Parameters:
response
- - JSON response from Google Geocoder Service- Returns:
- firstHit - First hit of
geocoderResult
- Throws:
GeocoderException
- - When GeocoderStatus unequal toGeocoderStatus.OK
com.github.openjson.JSONException
- - The JSONException is thrown by the JSON.org classes when things are amiss.
-
encode
public String encode(String address)
builds the google geo-coding url- Parameters:
address
-- Returns:
-
geocode
public GLatLng geocode(String address) throws IOException
Invoke a geocoder request to the GoogleMaps API.
Only return the first element ofgeocoderResult
to be backward compatible.
After successful call ofgeocode(String)
you can get all results fromgeocoderResult
- Parameters:
address
- - Requested address- Returns:
GLatLng
- only first hit of the request- Throws:
IOException
-
invokeService
protected InputStream invokeService(String address) throws IOException
fetches the url content- Parameters:
address
-- Returns:
- Throws:
IOException
-
getGecoderResult
public GeocoderResult getGecoderResult()
Get the Result of the last geocoder Request- Returns:
- the result of the last geocoder request
-
centerAndFitZoomForAdress
public void centerAndFitZoomForAdress(GMap map, String address) throws Exception
Convenience method to center and fit the zoom for an address, on the given map.Example:
GMap myMap = GMap("wicketId"); new Geocoder().centerAndFitZoomForAdress(myMap, "Frankfurt am Main");
Result:
Frankfurt is centered and the zoom is suitable- Parameters:
map
- - the map where the address should shownaddress
- - address as string for the google geocoder- Throws:
Exception
-
-