0

I am creating a search script that also pulls in the users latitude & longitude, which can also be uses as basis of the search. I achieve this by using an onLoad method that calls a javascript that should place the code into the form.

<body <?php body_class(); ?> onload="office_getLocation()">
<form name='office_address_search_home' method='post' action='http://domain.com   /address-search-test/#map' class='form-search'>
<input class='office_address_search_input_home input-medium search-query' name='office_address_search' style="height:12px;font-size: 12px;padding-top:5px;" onClick="this.value=''" value="Find Your Nearest Office" />
<input type='hidden' name='region' value='United Kingdom' />
<input type="hidden" name="office_latitude" id="office_latitude_id" value=""/>
<input type="hidden" name="office_longitude" id="office_longitude_id" value="" />
<input name='Submit' class='office_address_submit_home btn' type='submit' value='Search' style='height: 26px;line-height: 12px;' />
</form>

<script>
function office_getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
}
}

function showPosition(position)
{
document.getElementById("office_latitude_id").value = position.coords.latitude; 
document.getElementById("office_longitude_id").value = position.coords.longitude;
}
</script>

However it doesn't work.

I have echoed the results of showPosition(position) out (the position.coords.latitude & longitude) onto the screen and it is getting them okay, just not assigning them to the hidden values.

Any ideas? Will happily supply more data if need be.

Cheers

4

1 回答 1

0

我想通了:)

基本上,代码在上面工作。但是更新的地理位置值没有出现在源代码中。我通过将隐藏变量更改为文本框来测试这一点,并且 - 最终(在页面完成加载后一秒钟左右)它们出现了。此更改未反映在源代码中,但确实有效:)

不确定这对任何人有多大用处,但你去吧:)

于 2012-11-13T13:26:10.747 回答