2012-07-01 61 views
0

,當我有這樣的代碼應該留下一個標記,使用經緯度古怪異常放置標記與經緯度

... 
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 
+0

沒有足夠的文檔爲我檢查和發佈這個答案(除非它的工作!),但它不是'map.setCenter(位置);'?當'location'已經是'LatLng'時,爲什麼需要'getGeometry()。getLocation()'? –

+0

斑點! thx – outellou

+0

那是那個答案嗎?如果是,我會添加它來幫助別人。 –

回答

1

map.Center()需要LatLng,所以你不需要做現有的LatLng的任何轉換:

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

應該

map.setCenter(location); 
-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> 

使用這個腳本可能是它會幫助你。它爲我..

+0

我使用GWT。我的代碼有效,只是一個愚蠢的錯誤... – outellou