서브 클래스 SuggestBox
을 구현하여이 문제를 해결했습니다.이 서브 클래스는 SuggestOracle
입니다. AddressOracle
은 GWT 용 Google Maps API의 클래스 Geocoder
이 추상화를 제공하는 Google Maps Service의 래퍼 (Wrapper) 역할을합니다. 그래서 여기
내 솔루션입니다 :
먼저 Google지도 제안과 SuggestBox의 위젯을 구현
public class GoogleMapsSuggestBox extends SuggestBox {
public GoogleMapsSuggestBox() {
super(new AddressOracle());
}
}
그리고 우리는 지오 코더 비동기 방식 추상화 래핑 SuggestOracle 구현 :
을
class AddressOracle extends SuggestOracle {
// this instance is needed, to call the getLocations-Service
private final Geocoder geocoder;
public AddressOracle() {
geocoder = new Geocoder();
}
@Override
public void requestSuggestions(final Request request,
final Callback callback) {
// this is the string, the user has typed so far
String addressQuery = request.getQuery();
// look up for suggestions, only if at least 2 letters have been typed
if (addressQuery.length() > 2) {
geocoder.getLocations(addressQuery, new LocationCallback() {
@Override
public void onFailure(int statusCode) {
// do nothing
}
@Override
public void onSuccess(JsArray<Placemark> places) {
// create an oracle response from the places, found by the
// getLocations-Service
Collection<Suggestion> result = new LinkedList<Suggestion>();
for (int i = 0; i < places.length(); i++) {
String address = places.get(i).getAddress();
AddressSuggestion newSuggestion = new AddressSuggestion(
address);
result.add(newSuggestion);
}
Response response = new Response(result);
callback.onSuggestionsReady(request, response);
}
});
} else {
Response response = new Response(
Collections.<Suggestion> emptyList());
callback.onSuggestionsReady(request, response);
}
}
}
그리고 이것은 오라클 제안을위한 특별한 클래스입니다. 오라클 제안은 전달 된 주소가있는 String을 나타냅니다.
RootPanel.get("hm-map").add(new GoogleMapsSuggestBox());
:
class AddressSuggestion implements SuggestOracle.Suggestion, Serializable {
private static final long serialVersionUID = 1L;
String address;
public AddressSuggestion(String address) {
this.address = address;
}
@Override
public String getDisplayString() {
return this.address;
}
@Override
public String getReplacementString() {
return this.address;
}
}
지금 당신은 당신의 EntryPoint
- 클래스의 onModuleLoad()
-method에 다음 줄을 작성하여 웹 페이지에 새 위젯을 바인딩 할 수 있습니다