用LatLng放置标记时出现奇怪的异常 [英] Weird Exception when placing a marker with LatLng

查看:97
本文介绍了用LatLng放置标记时出现奇怪的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码应该使用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

 引起:com.google.gwt.core.client.JavaScriptException:(错误):属性< center>的值无效:http ://127.0.0.1:8888 / m3t / hosted.html?m3t 
,位于com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:248)
,位于com.google。 gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
位于com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
位于com.google。 gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:289)
位于com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
位于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 co m.tb.ttt.client.view.component.Map.setData(Map.java:85)
at com.tb.ttt.client.view.component.PopupMap.onAttach(PopupMap.java:95)
,位于com.google.gwt.user.client.ui.Widget.setParent(Widget.java:475)
位于com.google.gwt.user.client.ui.Panel.adopt(Panel.java :127)
在com.google.gwt.user.client.ui.ComplexPanel.add(ComplexPanel.java:97)
在com.google.gwt.user.client.ui.AbsolutePanel.add (AbsolutePanel.java:97)
,位于com.google.gwt.user.client.ui.PopupPanel $ ResizeAnimation.onInstantaneousRun(PopupPanel.java:344)
,位于com.google.gwt.user.client .ui.PopupPanel $ ResizeAnimation.setState(PopupPanel.java:239)
,位于com.google.gwt.user.client.ui.PopupPanel.show(PopupPanel.java:1010)
,位于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)
在com.google.gwt.event.dom.client.ClickEvent.dispatch(ClickEvent.java:54)
在com.google.gwt.event.dom.client.ClickEvent.dispatch(ClickEvent。 java:1)
在com.google.gwt.event.shared.GwtEvent.dispatch(GwtEvent.java:1)
在com.google.web.bindery.event.shared.EventBus.dispatchEvent( EventBus.java:40)
,位于com.google.web.bindery.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:193)
,位于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字节
请求标题
主机:127.0.0.1:8888
用户代理:Mozilla / 5.0(Windows NT 6.1; WOW64; rv:11.0)Gecko / 20100101 Firefox / 11.0
接受: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
连接:keep-alive
Referer:http://127.0.0.1:8888/m3t/hosted.html? m3t
Cookie:JSESSIONID = 1lkcmpo9v6f8j
响应标题
Content-Type:text / html; charset = iso-8859-1
Content-Length:1427


解决方案 div>

map.Center()需要一个 LatLng ,所以你不需要做任何转换现有 LatLng

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

应该是

  map.setCenter(位置); 


I have this code that should place a marker on a map using 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());

But instead I get an exception. It looks like that there is a %20 in the front of the Longitude

There is the 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

解决方案

map.Center() takes a LatLng, so you don't need to do any conversion of an existing LatLng:

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

should be

map.setCenter(location);

这篇关于用LatLng放置标记时出现奇怪的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆