org.wicketstuff.gmap.geocoder
Class Geocoder

java.lang.Object
  extended by 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
static String OUTPUT_JSON
           
static String OUTPUT_XML
           
 
Constructor Summary
Geocoder()
          Deprecated. since 22th June 2016 Google Maps requires an API-key, therefore you should use Geocoder(java.lang.String) instead of this constructor
Geocoder(com.fasterxml.jackson.databind.ObjectMapper mapper)
          Deprecated. since 22th June 2016 Google Maps requires an API-key, therefore you should use Geocoder(com.fasterxml.jackson.databind.ObjectMapper, java.lang.String) instead of this constructor
Geocoder(com.fasterxml.jackson.databind.ObjectMapper mapper, String apiKey)
           
Geocoder(String apiKey)
           
 
Method Summary
 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 in geocoderResult
 String encode(String address)
          builds the google geo-coding url
 GLatLng geocode(String address)
          Invoke a geocoder request to the GoogleMaps API.
Only return the first element of geocoderResult to be backward compatible.
After successful call of geocode(String) you can get all results from geocoderResult
 GeocoderResult getGecoderResult()
          Get the Result of the last geocoder Request
protected  InputStream invokeService(String address)
          fetches the url content
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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()
Deprecated. since 22th June 2016 Google Maps requires an API-key, therefore you should use Geocoder(java.lang.String) instead of this constructor

Default Constructor.
Create an ObjectMapper.
The ObjectMapper ignore unknown properties when mapping from JSON to POJO.
Use Geocoder(ObjectMapper) to customize


Geocoder

public Geocoder(String apiKey)

Geocoder

public Geocoder(com.fasterxml.jackson.databind.ObjectMapper mapper)
Deprecated. since 22th June 2016 Google Maps requires an API-key, therefore you should use Geocoder(com.fasterxml.jackson.databind.ObjectMapper, java.lang.String) instead of this constructor

Configuration Constructor.
If you have to customize the default ObjectMapper

See Also:
Geocoder()

Geocoder

public Geocoder(com.fasterxml.jackson.databind.ObjectMapper mapper,
                String apiKey)
Method Detail

decode

public GLatLng decode(String response)
               throws GeocoderException,
                      org.apache.wicket.ajax.json.JSONException
Decode an response of an geocoder request to POJOs.
Following the successful mapping from JSON to POJO
all hits are available in geocoderResult

Parameters:
response - - JSON response from Google Geocoder Service
Returns:
firstHit - First hit of geocoderResult
Throws:
GeocoderException - - When GeocoderStatus unequal to GeocoderStatus.OK
org.apache.wicket.ajax.json.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,
                       org.apache.wicket.ajax.json.JSONException
Invoke a geocoder request to the GoogleMaps API.
Only return the first element of geocoderResult to be backward compatible.
After successful call of geocode(String) you can get all results from geocoderResult

Parameters:
address - - Requested address
Returns:
GLatLng - only first hit of the request
Throws:
IOException
org.apache.wicket.ajax.json.JSONException

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 shown
address - - address as string for the google geocoder
Throws:
Exception


Copyright © 2016. All rights reserved.