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经度前面好像有一个

有 StackTrace

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()需要 a 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 回答