我有一个区域和经度/经度列表,我要求用户在他们访问我的网站时选择他们的位置.如果可能的话,我希望使用HTML5的地理位置预先填充他们的位置,但我不确定最好的方法.网上似乎缺少教程,至少从我能找到的内容来看.有没有人这样做过?你知道一个好的教程/资源吗?
更新
如果我有一堆城市的坐标,我如何使用javascript来确定最近的位置?
var array_of_functions = [
first_function('a string'),
second_function('a string'),
third_function('a string'),
forth_function('a string')
]
array_of_functions[0];
Run Code Online (Sandbox Code Playgroud)
这不能按预期工作,因为数组中的每个函数都是在创建数组时执行的.
通过执行以下操作来执行数组中任何函数的正确方法是什么:
array_of_functions[0]; // or, array_of_functions[1] etc.
Run Code Online (Sandbox Code Playgroud)
谢谢!
在下面的代码中,Clojure(1.2)正在打印错误的消息:
(try
(let [value "1,a"]
(map #(Integer/parseInt %) (.split value ",")))
(catch NumberFormatException _ (println "illegal argument")))
Run Code Online (Sandbox Code Playgroud)
这应该打印"非法参数",而是打印出来(1#<NumberFormatException java.lang.NumberFormatException: For input string: "a">.
我究竟做错了什么?
这是因为返回的懒惰序列map?怎么写?
有人可以发一个使用IndentParser的小例子吗?我想解析类似YAML的输入,如下所示:
fruits:
apples: yummy
watermelons: not so yummy
vegetables:
carrots: are orange
celery raw: good for the jaw
Run Code Online (Sandbox Code Playgroud)
我知道有一个YAML包.我想学习IndentParser的用法.
我这样初始化一个数组:
array = Array.new
array << '1' << '2' << '3'
Run Code Online (Sandbox Code Playgroud)
是否有可能一步到位?如果是这样,怎么样?
我无法为我的生活缠绕这个布局.我已经设法将按钮放到底部,但因为它们处于相对布局中,所以我不能让它们都达到50%.这是我到目前为止所做的,为了简化,删除了一些代码:
<ScrollView android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="50dip">
<LinearLayout android:id="@+id/LinearLayout02"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="15px">
<ImageView android:id="@+id/ImageView02"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginBottom="15px"
android:layout_gravity="center_vertical|center_horizontal|center"/>
<TextView
android:id="@+id/barcode"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/item_number"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/release"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/other_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/box_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true">
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:id="@+id/add_bt"
android:text="Add to Collection" />
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:id="@+id/back_bt"
android:text="Go Back" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我在WMI/WBEM接口上调用返回HRESULTS的方法.我想向用户显示这些错误代码的有意义的错误消息.但是,当我查找HRESULT的错误消息时,我只得到类似"IDispatch错误#3598"的字符串.
我可以找到这些IDispatch错误代码的列表来解释它们的含义吗?
可能发生错误的示例代码:
IWbemLocator *pLocator = NULL;
IWbemServices *pNamespace = NULL;
hr = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLocator);
if (FAILED(hr))
return hr;
hr = pLocator->ConnectServer(wPath, NULL, NULL, NULL, 0, NULL, NULL, &pNamespace);
if(FAILED(hr))
return hr;
Run Code Online (Sandbox Code Playgroud)
错误查找:
CString sMessage = _com_error(nError).ErrorMessage();
// sMessage now contains a string like "IDispatch error #3598"
Run Code Online (Sandbox Code Playgroud)
注意:这没有帮助 - 它不包含我得到的HRESULTS.它们都不包含在winerror.h中.
在我的Git仓库中,我更改了一些文件.我想把所有这些都放进去.但命令之间是否存在差异:
git add file1.php file2.php
git add .
Run Code Online (Sandbox Code Playgroud)
第二个命令是否只修改了文件或项目中的所有文件?或者这些命令是相同的?
我在这个主题上看到的每个例子都显示一个Button被绑定到一个命令,除了Button小部件是在一个类之外创建的:
例如:
from Tkinter import *
root = Tk()
def callback(event):
print "clicked at", event.x, event.y
frame = Frame(root, width=100, height=100)
frame.bind("<Button-1>", callback)
frame.pack()
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
现在没问题,除了我在尝试执行以下操作时遇到错误:
from Tkinter import *
class App():
def __init__(self,parent):
o = Button(root, text = 'Open', command = openFile)
o.pack()
def openFile(self):
print 'foo'
root = Tk()
app = App(root)
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
用"command = self.openFile()"或"command = openFile()"替换"command = openFile"也不起作用.
如何将函数绑定到我的类中的Button?
似乎每当我使用命令模式时,它总是导致比我不使用它时更多的类.这似乎很自然,因为我们在不同的类中一起执行相关代码块.如果我没有完成10或12个Command子类,我可能会认为这个项目本来只会使用6或7个类,否则不会打扰我.对于通常的7级项目,有19个左右的课程似乎差错了.
真正困扰我的另一件事是测试所有这些Command子类是一件痛苦的事.在我接到最后几条命令之后,我感到迟钝,好像我移动速度慢,不再灵活.
这对你来说听起来很熟悉吗?我做错了吗?我只是觉得我在这个项目的后期失去了敏捷,而且我真的不知道如何以前几天的速度不断地实施和测试.