首页 \ 问答 \ 直接更改谷歌地图标记图标?(Change google maps marker icon directly?)

直接更改谷歌地图标记图标?(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
更新时间:2022-12-02 12:12

最满意答案

这里有三个问题要考虑:如果用户希望某些输入无效,该怎么办? 如果无效输入是无意的,该怎么办? 以及该语言中常见的模式是什么?

当预期无效输入时

用户可能希望某些输入无效。 如果函数返回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 applying clamp(), 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 return NaN 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.

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用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)