如何将表单信息传递到单独页面上的谷歌地图上? [英] How to pass form information onto a google map on a separate page?
问题描述
我有两种形式,经纬度,即:
< form action =>
Latitude< input type =textname =latitude/>< br />
经度:< input type =textname =longitude/>< br />
< input type =submitvalue =继续>
< / form>
当我点击提交时,我想进入一个新的页面,标记以输入坐标为中心。
我知道如何绘制地图,我只是不确定如何将坐标从一个HTML页面转移到下一个一。有人可以展示一个快速示例吗?我假设应该有一个action = something和/或method =表单的东西,但我从来没有做过。
这是一个电话web应用程序。我不确定是否可以在该上下文中使用cookie。
定义您的< <$ c $ c>< form action =map.htmlmethod =GET>
当您提交表单时,您的网址应类似于以下内容,即X为纬度和经度值写在表格上。
http://www.example.com/map.html?latitute=X&longitue=X
然后,在 map.html
上写一段JavaScript,从URL中提取纬度和经度
信息。
以下示例由Artem Barger编写,摘自如何在JavaScript中获取查询字符串值?
function getParameterByName(name)
{
name = name.replace(/ [\ [] /,\\\\ [)。replace(/ [\]] /,\\\] );
var regexS =[\\?&]+ name +=([^&#] *);
var regex = new RegExp(regexS);
var results = regex.exec(window.location.search);
if(results == null)
return;
else
return decodeURIComponent(results [1] .replace(/ \ + / g,));
$ / code>
最后,如果你使用这个函数,你可能会这样做: p>
var latitude = getParameterByName(latitude);
var longitude = getParameterByName(latitude);
//将经度和纬度经度值传递给Google Maps API。
I have two forms, latitude and longitude, i.e.:
<form action="">
Latitude <input type="text" name="latitude" /><br />
Longitude: <input type="text" name="longitude" /><br />
<input type="submit" value="Continue">
</form>
When I click submit, I want to be taken to a new page on which is drawn a google map with a marker centered at the input coordinates.
I know how to draw the map, I'm just not sure how to transfer the coordinates from one HTML page to the next one. Can someone show a quick example? I'm assuming there's supposed to be an action=something and/or method=something for the form, but I've never done it before.
This is part of a phonegap webapp. I am not sure whether it is possible to use cookies in that context.
Define your <form>
method as GET
, like so:
<form action="map.html" method="GET">
When you submit the form your URL should look something like the following, being X the latitude and longitude values written on the form.
Then, on map.html
write a piece of JavaScript that extracts the latitude and longitude
information from the URL.
The following example was written by Artem Barger and was taken from How can I get query string values in JavaScript?
function getParameterByName(name)
{
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.search);
if(results == null)
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
Finally, if you use this function, you might do something like:
var latitude = getParameterByName("latitude");
var longitude = getParameterByName("latitude");
//Pass latitude and longitude vars to Google Maps API.
这篇关于如何将表单信息传递到单独页面上的谷歌地图上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!