0

LatLng を使用して地図上にマーカーを配置するこのコードがあります

    ...
geocoder = Geocoder.create();
myOptions = MapOptions.create();        
myOptions.setZoom(18);
myOptions.setMapTypeId(MapTypeId.HYBRID);
myOptions.setMapMaker(true);
map = GoogleMap.create(
    Document.get().getElementById("map_canvas"),myOptions);  
location = LatLng.create(45.48592686713835,-73.49009937672122);
map.setCenter(location.getGeometry().getLocation());
marker = Marker.create();
marker.setMap(map);
marker.setPosition(location.getGeometry().getLocation());
    location = LatLng.create(45.48592686713835,-73.49009937672122);
    map.setCenter(location.getGeometry().getLocation());
    marker = Marker.create();
    marker.setMap(map);
    marker.setPosition(location.getGeometry().getLocation());

しかし、代わりに例外が発生します。%20経度の手前にがあるようです

スタックトレースがあります

Caused by: com.google.gwt.core.client.JavaScriptException: (Error): Invalid value for property <center>: http://127.0.0.1:8888/m3t/hosted.html?m3t
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:248)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:289)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
    at com.google.maps.gwt.client.GoogleMap$.setCenter$(GoogleMap.java)
    at com.tb.ttt.client.view.component.Map.setMarker(Map.java:121)
    at com.tb.ttt.client.view.component.Map.codeAddress(Map.java:110)
    at com.tb.ttt.client.view.component.Map.setData(Map.java:85)
    at com.tb.ttt.client.view.component.PopupMap.onAttach(PopupMap.java:95)
    at com.google.gwt.user.client.ui.Widget.setParent(Widget.java:475)
    at com.google.gwt.user.client.ui.Panel.adopt(Panel.java:127)
    at com.google.gwt.user.client.ui.ComplexPanel.add(ComplexPanel.java:97)
    at com.google.gwt.user.client.ui.AbsolutePanel.add(AbsolutePanel.java:97)
    at com.google.gwt.user.client.ui.PopupPanel$ResizeAnimation.onInstantaneousRun(PopupPanel.java:344)
    at com.google.gwt.user.client.ui.PopupPanel$ResizeAnimation.setState(PopupPanel.java:239)
    at com.google.gwt.user.client.ui.PopupPanel.show(PopupPanel.java:1010)
    at com.google.gwt.user.client.ui.PopupPanel.center(PopupPanel.java:523)
    at com.tb.ttt.client.view.component.PopupMap.<init>(PopupMap.java:65)
    at com.tb.ttt.client.presenter.HpParamImmPresenter$3.onClick(HpParamImmPresenter.java:140)
    at com.google.gwt.event.dom.client.ClickEvent.dispatch(ClickEvent.java:54)
    at com.google.gwt.event.dom.client.ClickEvent.dispatch(ClickEvent.java:1)
    at com.google.gwt.event.shared.GwtEvent.dispatch(GwtEvent.java:1)
    at com.google.web.bindery.event.shared.EventBus.dispatchEvent(EventBus.java:40)
    at com.google.web.bindery.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:193)
    at com.google.web.bindery.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:88)
    at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:127)
    ... 31 more
[WARN] 404 - GET /(45.48592686713835,%20-73.49009937672122) (127.0.0.1) 1427 bytes
   Request headers
      Host: 127.0.0.1:8888
      User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0
      Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
      Accept-Language: en-us,en;q=0.5
      Accept-Encoding: gzip, deflate
      Connection: keep-alive
      Referer: http://127.0.0.1:8888/m3t/hosted.html?m3t
      Cookie: JSESSIONID=1lkcmpo9v6f8j
   Response headers
      Content-Type: text/html; charset=iso-8859-1
      Content-Length: 1427
4

2 に答える 2

1

map.Center()を取るLatLngので、既存の を変換する必要はありませんLatLng:

map.setCenter(location.getGeometry().getLocation());

する必要があります

map.setCenter(location);
于 2012-07-01T18:47:51.970 に答える
-1
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css">
        <script src="http://maps.googleapis.com/maps/api/js?sensor=false" type="text/javascript"></script>
        <script type="text/javascript">
            var map;
            function initialize() {
                var mapOptions = {
                    center: new google.maps.LatLng(45.48592686713835,-73.49009937672122),
                    zoom: 18,
                    mapTypeId: google.maps.MapTypeId.SATELLITE,
                    heading: 90,
                    tilt: 45
                };
                map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
                var location = new google.maps.LatLng(45.48592686713835,-73.49009937672122);
                var marker = new google.maps.Marker({
                    position: location,
                    map: map
                });
                marker.setTitle("Title");
                var infowindow = new google.maps.InfoWindow(
                { content: "Message",
                    size: new google.maps.Size(50,50)
                });
                google.maps.event.addListener(marker, 'click', function() {
                    infowindow.open(map,marker);
                });
            }

            function rotate90() {
                var heading = map.getHeading() || 0;
                map.setHeading(heading + 90);
            }

            function autoRotate() {
                // Determine if we're showing aerial imagery
                if (map.getTilt() != 0) {
                    window.setInterval(rotate90, 3000);
                }
            }

            google.maps.event.addDomListener(window, 'load', initialize);
        </script>

このスクリプトを使用すると役立つ場合があります。わたしにはできる..

于 2012-07-01T18:24:55.930 に答える