坐标数组(Array of Coordinates)
我在javascript中有一个坐标数组,声明为
path1 = new Array();
没有大小。 我将只从我的Android应用程序推送坐标发送并使用此数组作为我的折线的路径。现在我的问题是,数组中有多少元素有限制吗?
我尝试跟踪我的gps,前几个坐标工作正常。 我可以看到我的折线。 但突然间折线会消失。
任何帮助将不胜感激。 对不起,我的英语不好。
enter code herefunction path(sender,latitude,longitude,speed,id,path,color,plength){ var latlng = new google.maps.LatLng(latitude,longitude); var polyPath = polyArray(path); createPoly(polyPath,color); createMarker(latlng,sender,speed,plength); } function polyArray(path){ var array = path.split(','); var path1 =new Array(); for(var i=0;i<=array.length;i=i+2){ var coordinates = new google.maps.LatLng(array[i],array[i+1]); path1.push(coordinates); } return path1; } function createPoly(path,color){ var polyOptions = { path:path, strokeColor: color, strokeOpacity: 1.0, strokeWeight: 1 }; poly = new google.maps.Polyline(polyOptions); poly.setMap(map); } function createMarker(latlng,sender,speed,plength){ var marker = new google.maps.Marker({ position: latlng, map: map }); var infowindow = new google.maps.InfoWindow({content:sender + "\n" + speed + "m/s"}); infowindow.open(map, marker); markers.push(marker); for(var i=0;i<markers.length-plength;i++) markers[i].setMap(null); } google.maps.event.addDomListener(window, 'load', initialize);
I have an array of coordinates in javascript declared as
path1 = new Array();
with no size. I will just push the coordinates send from my android application and use this array as a path for my polyline.Now my question is, is there a limit on how many elements in an array?
I try to track my gps and the first few coordinates works fine. I can see my polyline. But suddenly the polyline will disappear.
Any help will be appreciated. Sorry for my bad english.
enter code herefunction path(sender,latitude,longitude,speed,id,path,color,plength){ var latlng = new google.maps.LatLng(latitude,longitude); var polyPath = polyArray(path); createPoly(polyPath,color); createMarker(latlng,sender,speed,plength); } function polyArray(path){ var array = path.split(','); var path1 =new Array(); for(var i=0;i<=array.length;i=i+2){ var coordinates = new google.maps.LatLng(array[i],array[i+1]); path1.push(coordinates); } return path1; } function createPoly(path,color){ var polyOptions = { path:path, strokeColor: color, strokeOpacity: 1.0, strokeWeight: 1 }; poly = new google.maps.Polyline(polyOptions); poly.setMap(map); } function createMarker(latlng,sender,speed,plength){ var marker = new google.maps.Marker({ position: latlng, map: map }); var infowindow = new google.maps.InfoWindow({content:sender + "\n" + speed + "m/s"}); infowindow.open(map, marker); markers.push(marker); for(var i=0;i<markers.length-plength;i++) markers[i].setMap(null); } google.maps.event.addDomListener(window, 'load', initialize);
原文:https://stackoverflow.com/questions/21108227
最满意答案
看下面的例子:
enum E1 { e1 }; enum E2 { e2 }; public class Test <E extends Enum> { List<E> list = new ArrayList<>(); void add(E e) { list.add(e); } void dump() { System.out.println(list); } public static void main(String[] args) throws Exception { Test<Enum> test = new Test<>(); test.add(E1.e1); test.add(E2.e2); test.dump(); } }
你可以声明一个列表来接受“任何枚举”; 因为任何枚举类都必须从Enum派生,您可以使用该特定类来实例化一个Test,以允许添加来自枚举类的枚举常量。
当然,这更像是一个“代码难题”; 因为我认为这样的设计非常谨慎; 不是我在“真实世界生产”代码中会做的事情。
See the following example:
enum E1 { e1 }; enum E2 { e2 }; public class Test <E extends Enum> { List<E> list = new ArrayList<>(); void add(E e) { list.add(e); } void dump() { System.out.println(list); } public static void main(String[] args) throws Exception { Test<Enum> test = new Test<>(); test.add(E1.e1); test.add(E2.e2); test.dump(); } }
You can declare a list to accept "any enum"; and as any enum class must be derived from Enum, you can then use that specific class to instantiate a Test that allows to add enum constants coming from enum classes.
Of course, this is more of a "code puzzle"; as I would regard such a design with a lot of caution; not something that I would do in "real world production" code.
相关问答
更多-
Enums需要多少内存?(How much memory do Enums take?)[2022-12-27]
在Java中, enum是一个完整的类 : Java编程语言枚举类型比其他语言的类型更强大。 枚举声明定义一个类(称为枚举类型)。 枚举类体可以包括方法和其他字段。 为了查看每个enum的实际大小,让我们做一个实际的enum并检查它创建的class文件的内容。 假设我们有以下Constants枚举类: public enum Constants { ONE, TWO, THREE; } 编译上面的enum并用javap反汇编生成的class文件如下: Compiled from "Consta ... -
创建枚举列表?(Creating List of Enums?)[2022-08-05]
我猜想你想要枚举本身的名字,而不是他们的价值观。 因此,请尝试以下代码: public static void main (String[] args) throws java.lang.Exception { List> myEnums = new ArrayList<>(); myEnums.add(Outlook.class); myEnums.add(Temperature.class); myEnums.add(Humid ... -
一个明显的方法是功能注释。 class CheckBox(enum.Enum): Off = 0 On = 1 def setCheckState(self, value: CheckBox): ... 这清楚地表明value应该是CheckBox一个实例。 拥有Enum只会Enum更容易一些。 但是,2.7中没有直接支持注释本身。 常见的解决方法包括将该信息放在函数文档字符串(各种工具可以找到它)或注释中(我们已经知道)。 如果要为自己的代码寻找方法:使用注释装饰器。 这具有继 ...
-
最通用的解决方案是使用TreeSet,它在插入时按照排序顺序保存项目。 如果你没有提供比较器,那么它将保持“自然顺序”,这对于枚举是它们被声明的顺序。由于该顺序容易改变,所以最好的选择是使用自定义比较器声明TreeSet根据需要命令它们。 当然,如果你只有3个枚举,并且每个集合最多只有一个枚举,那么你可能会很懒惰,并按照正确的顺序手动将它们放入EnumSet中,但TreeSet可能是长期的“正确”方法。 The most general solution is to use a TreeSet, which ...
-
尝试这个: public void AddAssitant(Assistant assistant, ArrayList list) { if(assistant.Salary >= 150) { list.Add(assistant); } } Try this: public void AddAssitant(Assistant assistant, ArrayList list) { if(assistant.Salary >= 150) ...
-
我认为这会奏效 while(!Front.get(front).isEmpty()){ Q.clear(); for(int i=0;i看下面的例子: enum E1 { e1 }; enum E2 { e2 }; public class Test
{ List list = new ArrayList<>(); void add(E e) { list.add(e); } void dump() { System.out.println(list); } public static void main(String[] args) throws Exception { ... 那些枚举类看起来很整洁,我常常嫉妒Java的枚举。 我认为通常的规则适用:做最简单的事可能有效。 如果你发现自己在枚举上有多个switch ,那就是气味,是时候考虑你找到的模式了。 否则,为什么要为自己增加一些你不需要的东西呢? Those Enumeration Classes look neat, I've often looked jealously at Java's enums. I think the usual rules apply: do the Simplest Thing That C ...roslyn能生成枚举吗?(Can roslyn generate enums?)[2023-04-06]
这是你用roslyn创建枚举的方法; class Program { static void Main(string[] args) { var member1 = Syntax.EnumMemberDeclaration( identifier: Syntax.Identifier("Member1") ); var declaration = Syntax.EnumDeclaration( ...我假设Roach extends Mob 。 您可以使用ArrayList来保存Roach es。 所以: public RoachSpawner(Level level) { super(level); mobs = new ArrayList (); } 如果您只是在所有实现中使用ArrayList ,您可以在基础中分配它(假设ArrayList始终是您想要的容器 - 如果您想使用其他List类型,请参阅kwah的答案并创建子类的子类) : public c ... 相关文章
更多- POJ 1408 Fishnet(几何--叉积求面积 + 求直线的交点坐标)
- Java 数组
- 怎么得到String数组?
- scala数组操作
- 报错说找不到abbrev这个方法,但Array有这个方法的吧?
- 微信如何根据经纬度坐标查询具体地理位置
- 动态拼接JSON数组的问题
- java数组的遍历
- HTML5-canvas画布坐标体系_HTML5网页游戏坦克大战04
- Lua 数组操作
最新问答
更多- 您如何使用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)