- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试获取两个位置,使用 Google Maps API 中的 directionsService.route
查找两点之间的路线,然后将返回的路线对象存储在 localStorage 中以供稍后使用使用。我正在尝试使用下面的解决方案(对于一个有点不相关的问题),但它在最后两行失败,因为 .extend()
、.getNorthEast()
和.getSouthWest()
存储在 Google 对象的原型(prototype)中。这些方法有助于在组合多个行程时设置新 map 的边界。
if (count == 0) {
combinedResults = unsortedResults[key].result;
} else {
// only building up legs, overview_path, and bounds in my consolidated object. This is not a complete
// directionResults object, but enough to draw a path on the map, which is all I need
combinedResults.routes[0].legs = combinedResults.routes[0].legs.concat(unsortedResults[key].result.routes[0].legs);
combinedResults.routes[0].overview_path = combinedResults.routes[0].overview_path.concat(unsortedResults[key].result.routes[0].overview_path);
combinedResults.routes[0].bounds = combinedResults.routes[0].bounds.extend(unsortedResults[key].result.routes[0].bounds.getNorthEast());
combinedResults.routes[0].bounds = combinedResults.routes[0].bounds.extend(unsortedResults[key].result.routes[0].bounds.getSouthWest());
}
当您运行 JSON.stringify()
到 JSON.parse()
转换时,我尝试了多种解决方法来保存原型(prototype)函数,但没有任何效果。
更新
我尝试使用这个add-on帮助保留原型(prototype)函数,它确实如此,但我认为不可能在序列化/反序列化后将这些函数重新添加回 JS 对象,因为该对象已经是 initialized
var serializer = new ONEGEEK.GSerializer();
var s = serializer.serialize(result.routes[0].bounds);
var d = serializer.deserialize(s);
我最终做的是一个有点黑客的解决方法来模仿需要一些原型(prototype)函数的 bounds.extend()
函数(如下)。此解决方案的唯一问题是,如果我需要与缓存对象进行交互以进行其他操作,我将处于相同的位置
var existing = combinedResults.routes[0].bounds;
var adding = trip2.routes[0].bounds;
existing.north = existing.north > adding.north ? existing.north : adding.north;
existing.south = existing.south < adding.south ? existing.south : adding.south;
existing.east = existing.east > adding.east ? existing.east : adding.east;
existing.west = existing.west < adding.west ? existing.west : adding.west;
最佳答案
基本上根本不可能用 JSON 存储函数。
要恢复原始的LatLngBounds
,您只需使用存储的LatLngBoundsLiteral作为参数创建一个新的LatLngBounds()
:例如
var json=JSON.parse(//stored string
'{"bounds:{"south":41.9029,"west":2.3,"north":55.7,"east":37.6}}');
json.bounds=new google.maps.LatLngBounds(json.bounds);
关于javascript - 使用 JSON.stringify 时将原型(prototype)函数添加回返回的 Google Maps API 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35464037/
我从 https://github.com/douglascrockford/JSON-js/blob/master/json2.js 下载了 JSON2.js并且它没有 JSON2.stringif
我制作了一个 Stringify 协议(protocol),将实现该协议(protocol)的类型转换为字符串。 protocol Stringify { func stringify() -
在我的Reaction Native 0.70应用程序中有一些不可序列化的东西,它在上下文API中传递,以使它们可用于以下组件。以下是它的代码:。在可能需要检索不可序列化值的组件中:。但是,它在组件中
MISRA 标准不允许在宏定义中使用字符串化运算符在不使用 # 运算符的情况下实现相同概念的替代方法是什么? 最佳答案 实际上并没有任何直接的替代方案——只有变通办法。此建议规则与建议不要使用类似函数
MISRA 标准不允许在宏定义中使用字符串化运算符在不使用 # 运算符的情况下实现相同概念的替代方法是什么? 最佳答案 实际上并没有任何直接的替代方案——只有变通办法。此建议规则与建议不要使用类似函数
前言 JSON是一种轻量级数据格式,可以方便地表示复杂数据结构。JSON对象有两个方法:stringify()和parse()。在简单的情况下,这两个方法分别可以将JavaScript序列化
...使用 JSON2.js 和 JQUERY 正如您从第一张图片中看到的,对象属性 customerReport.Title 有撇号。在代码中你可以看到我正在调用 JSON.stringify()
我目前正在调查为什么 JSON.stringify() 没有正确解析我的对象。这是我试图解析为 JSON 字符串的对象: var data = [{ name: string, act
问题 大家好,有人可以帮我解决这个复杂的问题吗? :我正在使用 Spring boot v2.0.5 和 React.js v15.6.2、ReactDom v15.6.2、React Bootstr
我正在使用 Knockout.js 和 ASP.NET web ApiController 完成一个新项目。我看到的许多示例在将数据发布到服务器之前执行一些手动 JSON 序列化。此外,请求内容类型同
此宏在调用时编译: macro_rules! remote_optional { ($remote:ident with=$def:ident $def_str:expr) => {
我有一个返回对象,需要打印一些属性,但 JSON.stringify 无法识别一些属性。 例如: Object = {"Date":"Mon, 22 Jun 2015 10:56:50 GMT","C
JSON.stringify( ) 是否等同于序列化或有效序列化,或者它只是实现的必要步骤序列化? 换句话说,JSON.stringify( ) 是否足够但不需要序列化?还是必要但不充分?还是 Jav
JSON.stringify是我们经常用到的的一个方法,它主要作用是将 JavaScript 值和对象转换为字符串。如: JSON.stringify({ foo: "bar&
GCC 似乎总是在源代码中用空格扩展制表符。它保留表达式内部的空间。标准对此有何规定? 例如,c 会是什么?此示例中包含( 表示源代码文件中的乱码 \t 字符)。 #define X(a) #a co
根据this答案,JSON.parse() 的时间复杂度是 O(n) . 这是否适用于 JSON.stringify() ?似乎没有任何地方记录这一点。 最佳答案 它应该是 O(n),但是 n是被字符
connection.query( 'SELECT DeskName FROM desks WHERE stat = ?',["Booked"], function(err, rows){ if(
我们正在根据一种简单的模板格式构建动态 JSON 有效负载,该格式指示我们的有效负载应产生多少级别,例如"level1.level2"> 将产生: { "level1": [ {
我对 Node.js 和传递 JSON 数据相当陌生,但是有人可以让我深入了解为什么我不需要在其中执行 JSON.stringify 。 module.exports.getBusinessOffer
我有一个简单的 JavaScript 对象,其中包含一些设备信息,包括最后已知的地理位置(仅经度和纬度)。我正在使用 JSON.stringify 将此对象转换为 JSON,但我拥有的一个不是 boo
我是一名优秀的程序员,十分优秀!