直接更改谷歌地图标记图标?(Change google maps marker icon directly?)
我想直接更改我的谷歌地图标记图像当一些链接点击..我的默认标记图像是..
var marke = new google.maps.Marker({ map: map, animation: google.maps.Animation.DROP, title:"Klik disini", draggable:true, icon:"http://localhost/pinMarker/img_marker.png" });
我想将图标
"img_marker.png"
更改为另一张图片......我在哪里可以用javascript实现我想要的?任何链接都在讨论这个问题?
谢谢
i want to change my google maps marker image directly when some link was click..my default marker image is..
var marke = new google.maps.Marker({ map: map, animation: google.maps.Animation.DROP, title:"Klik disini", draggable:true, icon:"http://localhost/pinMarker/img_marker.png" });
i want to change icon
"img_marker.png"
to be another image...where can i achieve what i want with javascript?any link discuss about that?
thanks
原文:https://stackoverflow.com/questions/17169848
最满意答案
这里有三个问题要考虑:如果用户希望某些输入无效,该怎么办? 如果无效输入是无意的,该怎么办? 以及该语言中常见的模式是什么?
当预期无效输入时
用户可能希望某些输入无效。 如果函数返回
NaN
,则这些情况很容易处理。let values = [[2, 4, 6], [3, 5, 1], [7, 5, 9]]; let clamped = values.map(args => clamp(...args)).filter(n => !isNaN(n)); console.log(clamped); // [4, 7]
如果该函数抛出异常,则用户必须使用
try...catch
语句 ,这将更加冗长且性能更低。 或者她可以在应用clamp()
之前过滤掉无效输入,但是她必须确切地知道哪种输入是无效的,这可能比在这个例子中更复杂。这显然是支持
NaN
选项的一个观点。无效输入无意时
如果函数抛出异常,则可以更轻松地调试部分用户的正版错误。 例如,用户可能很容易犯这样的错误:
clamp(-4, 0, -10);
如果以上是返回
NaN
,调试可能是噩梦,特别是在一个包含很多其他事情的大型代码库中。 如果函数抛出异常,用户会看到:RangeError: min may not be greater than max at clamp ...
更简单。 这显然是一场胜利。
共同的语言模式
所以我们有一个平局。 我们最好的办法是问自己,WWJD(JavaScript会做什么)? 例如,当我们将负数传递给
Math.sqrt()
时会发生什么?console.log(Math.sqrt(-4)); // NaN
它返回
NaN
。 这是打破平局。 如果输入无效,JavaScript程序员会期望这些函数返回NaN
。 它们将用于处理源自此行为的错误,如果不是,那么他们最好习惯它。所以回归
NaN
。There are three questions to consider here: What if the user expects some inputs to be invalid? What if the invalid inputs are unintentional? and What patterns are commonly found in the language?
When invalid inputs are expected
The user might expect certain inputs to be invalid. If the function returns
NaN
, these cases are easy to deal with.let values = [[2, 4, 6], [3, 5, 1], [7, 5, 9]]; let clamped = values.map(args => clamp(...args)).filter(n => !isNaN(n)); console.log(clamped); // [4, 7]
If the function were to throw an exception, the user would have to use a
try...catch
statement, which would be more verbose and less performant. Or she could filter out the invalid inputs before applyingclamp()
, but then she would have to know exactly which kinds of inputs are invalid, which could be more complicated than it is in this example.This is clearly a point in favor of the
NaN
option.When invalid inputs are unintended
Genuine errors on part of the user will be more easily debugged if the function throws an exception. For example, the user could easily make a mistake like this:
clamp(-4, 0, -10);
If the above were to return
NaN
, debugging could be nightmarish, especially in a large code base with lots of other things going on. If the function were to throw an exception, the user would see this:RangeError: min may not be greater than max at clamp ...
Much simpler. This is clearly a win for
throw
.Common language patterns
So we have a tie. Our best bet is to ask ourselves, WWJD (What would JavaScript do)? What happens, for example, when we pass a negative number to
Math.sqrt()
?console.log(Math.sqrt(-4)); // NaN
It returns
NaN
. This is the tie-breaker. JavaScript programmers will expect functions like these to returnNaN
if the inputs are invalid. And they will be used to dealing with errors that originate from this behavior, or if not, then they had better get used to it.So return
NaN
.
相关问答
更多-
您不需要在throw后放置return语句, return行将永远不会被触发,因为立即手动控制回调用程序。 You do not need to put a return statement after throw, the return line will never be reached as throwing an exception immediately hands control back to the caller.
-
我的JavaScript API是否应该抛出或返回无效输入的值?(Should my JavaScript API throw or return a value on invalid inputs?)[2024-01-03]
这里有三个问题要考虑:如果用户希望某些输入无效,该怎么办? 如果无效输入是无意的,该怎么办? 以及该语言中常见的模式是什么? 当预期无效输入时 用户可能希望某些输入无效。 如果函数返回NaN ,则这些情况很容易处理。 let values = [[2, 4, 6], [3, 5, 1], [7, 5, 9]]; let clamped = values.map(args => clamp(...args)).filter(n => !isNaN(n)); console.log(clamped); // ... -
您可以在任何 jQuery对象上调用的简单且可重用的 jQuery函数: $.fn.clearErrors = function () { $(this).each(function() { $(this).find(".field-validation-error").empty(); $(this).trigger('reset.unobtrusiveValidation'); }); }; 用法: question.clearErrors(); 选项 ...
-
通过Javascript分配出来,但是放到
throw循环中(Distribute the out but into the [2023-07-18]throw loops by Javascript) 首先:永远不要使用相同的ID两次! 本质上,问题在于你插入了几行代码,但是你想操作几个不同HTML标签的innerHTML。 你所做的是:content取而代之的是:
morecontent
contentmorecontent您可以尝试在回调中执行console.log: var info = api.getBridge(); 但在你的回调中: var callbackvalue = hue.nupnpSearch(function(err, result) { if (err) throw err; return result; }); console.log(callbackvalue); 好了,现在你知道你的函数返回了什么。 要进一步使用此“returnvalue”,您只需调用处理结果 ...JavaScript输入(JavaScript Inputs)[2021-12-21]
首先,您没有ID为“numberOfWallsInput”的元素; 您的input元素的name为numberOfWallsInput。 将其添加为ID,或使用getElementsByName()代替。 然后你需要拉value ,而不仅仅是元素: var x = document.getElementsByName("numberOfWallsInput")[0]; document.getElementById("demo").innerHTML = x.value; JSFiddle演示 。 Fir ...记得: 包装函数是软件库或计算机程序中的子例程,其主要目的是在很少或不需要额外计算的情况下调用第二个子例程或系统调用 。 如维基百科上所见 。 所以我建议你做第一件事,让API处理它。 每当我使用包装器时,我只想查看实际API的文档,而不是包装器。 对我来说,它似乎也更直观。 祝你好运 :) Remember: A wrapper function is a subroutine in a software library or a computer program whose main purpose i ...javascript中匿名函数的索引和值输入的说明(Explanation for index and value inputs to anonymous function in javascript)[2022-01-23]
这就是jQuery .prop()方法的实现方式。 如果它看到第二个参数是一个函数,它会为每个匹配的元素调用你的函数,传递元素索引和属性值。 在JavaScript中创建API涉及针对涉及API客户端将使用的回调的所有情况做出类似的决策。 一般而言,没有严格的规则,尽管某些情境可能会遵循惯例。 一个例子是Node世界,其中回调传递两个参数,一个(可能为null) error和与操作相关的数据是很常见的。 It's just how the jQuery .prop() method is implement ...点击此链接http://www.iceycake.com/2012/06/xml-json-jsonp-web-service-endpoints-spring-3-1/ 或者以这种简单的方式尝试 @RequestMapping(value = "/mobile_getcountrylist", method = RequestMethod.GET, produces = {"application/x-javascript"}) @ResponseBody public Object ...您可以创建一个操作并将其添加到管道中,该管道检查ModelState.IsValid并将400状态返回给客户端。 You could create an action and add it to your pipeline, that checks ModelState.IsValid and throws a 400 status back to the client.相关文章
更多- 应用多个icon的对比
- google weather 图标
- Guava学习笔记:Google Guava 类库简介
- Ext grid 出现checkbox和图标移位的问题(在IE)
- Google TTS(文字转语音)api 2
- Google Gson库的主要操作类Gson详解
- 最简单下拉刷新,Google最新(可刷新任何控件)
- 十分钟了解分布式计算:Google Dataflow
- pychseg - A Python Chinese Segment Project - Google Project Hosting
- 【原创】小白学jquery Mobile《构建跨平台APP:jQuery Mobile移动应用实战》连载五(给按钮加图标)
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)