【发布时间】:2014-07-10 15:37:30
【问题描述】:
如何将家庭地址直接自动显示到谷歌地图(maps.google.com)并显示到谷歌地图的搜索栏中?这个家庭地址来自另一个纯 JAVASCRIPT 的网站 (UAT)?请帮我。我是那个PL的新手,所以我不熟悉。谢谢
例子:
在另一个网站有一个家庭地址的文本字段,输入的地址是:
345 Bury Village Oslo St. Bershka City, Switzerland
我想在 Google 地图中复制/显示整个家庭住址并自动搜索该地址
这是我正在使用的代码:
function scanLapVerification() {
try {
var forAlert = '';
var el = getElement(document, "class", "workflowActivityDetailPanel", "");
if (el && el.length > 0) {
var eltr = getElement(el[0], "tag", "tr", "");
if (eltr && eltr.length > 0) {
//Read Contact and Permanent address
var addresses = {
CA: { province: null, municipality: null, barangay: null, zip: null, street: null, snumber: null, building: null, floor: null}
,PA: { province: null, municipality: null, barangay: null, zip: null, street: null, building: null, bnumber: null, floor: null}
};
var address_type = null;
for (var i = 0; i < eltr.length; i++) {
tr_text = eltr[i].innerText;
if (tr_text.substr(0, "Contact address".length) == "Contact address") address_type = "CA";
if (tr_text.substr(0, "Permanent address".length) == "Permanent address") address_type = "PA";
if (address_type && tr_text.substr(0, "Province".length) == "Province") {
addresses[address_type].province = tr_text.substr("Province".length, tr_text.length - "Province".length);
forAlert = forAlert + 'Province: '+ addresses[address_type].province + ',' + address_type + ' > ';
}
if (address_type && tr_text.substr(0, "Municipality".length) == "Municipality") {
addresses[address_type].municipality = tr_text.substr("Municipality".length, tr_text.length - "Municipality".length);
forAlert = forAlert + 'Municipality: '+ addresses[address_type].municipality + ',' + address_type + ' > ';
}
if (address_type && tr_text.substr(0, "Barangay".length) == "Barangay") {
addresses[address_type].barangay = tr_text.substr("Barangay".length, tr_text.length - "Barangay".length);
forAlert = forAlert + 'Barangay: ' + addresses[address_type].barangay + ',' + address_type + ' > ';
}
if (address_type && tr_text.substr(0, "ZIP Code".length) == "ZIP Code") {
addresses[address_type].zip = tr_text.substr("Zip Code".length, tr_text.length - "ZIP Code".length);
forAlert = forAlert + 'ZIP Code: ' + addresses[address_type].zip + ',' + address_type + ' > ';
}
if (address_type && tr_text.substr(0, "Street name".length) == "Street") {
addresses[address_type].street = tr_text.substr("Street name".length, tr_text.length - "Street".length);
forAlert = forAlert + 'Street name: ' + addresses[address_type].street + ',' + address_type + ' > ';
}
if (address_type && tr_text.substr(0, "Street number".length) == "Street number") {
addresses[address_type].snumber = tr_text.substr("Street number".length, tr_text.length - "Street number".length);
forAlert = forAlert + 'Street number: ' + addresses[address_type].snumber + ',' + address_type + ' > ';
}
if (address_type && tr_text.substr(0, "Building name".length) == "Building name") {
addresses[address_type].building = tr_text.substr("Building".length, tr_text.length - "Building name".length);
forAlert = forAlert + 'Building name: ' + addresses[address_type].building + ',' + address_type + ' > ';
}
if (address_type && tr_text.substr(0, "Floor number".length) == "Floor number") {
addresses[address_type].floor = tr_text.substr("Zip".length, tr_text.length - "Floor number".length);
forAlert = forAlert + 'Floor number: ' + addresses[address_type].floor + ',' + address_type + ' > ';
}
}
//Open a new tab for Google Maps
In this place need to put the code for New tab
//Enter full address into search input
In this place need to put the code for Displaying the Home Address from another website into Google Maps search bar automatically
}
}
return { status: "KO" };
} catch (e) {
alert("Exception: scanLapVerification\n" + e.Description);
return { status: "KO", message: e };
}
};
【问题讨论】:
标签: javascript google-maps google-search