在自定义 Google 地图中添加按邮政编码搜索

发布于 2024-07-26 06:27:43 字数 671 浏览 10 评论 0原文

首先我想说,我是这个网站的新手,从未使用过 Google Maps API,并且对 JavaScript 有一定的了解。

我做了什么: 我通过向 Google“我的地图”添加位置来组合自定义“商店定位器”。 然后,我创建了一个带有下拉菜单的网页,根据您从下拉菜单中选择的位置,它会更改保存地图的 iFrame 的 SRC。 因此,当页面加载时,您会看到更大比例的地图,并且通过选择特定位置,它会将地图更改为该特定位置(缩放和裁剪)。

我需要做什么: 现在要完成此地图,我需要做的是添加“按邮政编码搜索”,这将允许用户输入邮政编码,并使网页返回最近位置的列表以及希望它们的距离。

有人知道我是否能够将“按邮政编码搜索”功能添加到我的自定义 Google 地图中吗?

我的代码确实没有太多要发布的内容,但如果有帮助,我很乐意这样做。 我的地图的当前功能运行良好,问题是我不知道从哪里开始添加邮政编码搜索。

这是我引用的页面的链接: http://74.53.82.155/store-locator .htm

感谢任何帮助。

提前致谢, 混沌

First I would like to say that I am new to this site, never worked with Google Maps API and have an intermediate knowledge of JavaScript.

What I have done:
I put together a custom 'store locator' by adding locations to a Google 'my maps'. I then created a web page with a drop down menu and depending on the location you select from the drop down, it changes the the SRC for the iFrame holding the map. So when the page loads you see a larger scale map and by selecting specific locations, it will change the map to that specific location (zoom and crop).

What I need to do:
What I need to do now to complete this map is to add a 'search by zip code' which will allow the user to put in their zip code and have the web page return a list of the closest locations and hopefully their distances.

Does anyone have an idea if I will be able to add the 'search by zip' functionality to my custom Google map?

There really isn't much to my code to post, but if it will help, I'll gladly do so. The current functionality of my map works great, the problem is that I don't know where to begin adding the zip code search.

Here is a link to the page that I am referring to: http://74.53.82.155/store-locator.htm

Any help is appreciated.

Thanks in advance,
gnrlchaos

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

紫﹏色ふ单纯 2024-08-02 06:27:43

一种选择是使用 geonames Web 服务,该服务根据邮政编码返回位置。 下面是如何通过 dojo 使用该 Web 服务的快速示例。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title></title>
        <link rel="stylesheet" type="text/css" href="layout.css">
        <script type="text/javascript">var djConfig = { parseOnLoad: true }</script>
        <script type="text/javascript" src="../dojo-release-1.3.0/dojo/dojo.js"></script>
        </script>
        <script type="text/javascript">
            dojo.require("dojo.io.script");
                function getPlace() {
        var zip = dojo.byId('zipcode').value;
        console.log('zip is ', zip);
        //use country code to get results for a specific country
        //var gn_url = 'http://ws.geonames.org/postalCodeLookupJSON?postalcode=' + zip + '&country=US';
        var gn_url = 'http://ws.geonames.org/postalCodeLookupJSON?postalcode=' + zip;
        console.log(gn_url);
        dojo.io.script.get({
          url: gn_url, 
          callbackParamName: "callback",
          load:function(response, io) { 
            console.log('got json.'); 
            console.dir(response); 
            places = response.postalcodes; 
            var infos = []
            dojo.forEach(places, function(p, i) {
                infos[i] = p.placeName + ', ' + p.adminName1 + ', Lat: ' + p.lat + '; Long: ' + p.lng + '<br />';
            });
                dojo.byId('postalCode').innerHTML = infos.join('');
          }, 
          error:errorCb
        });   
        }

        function errorCb(type, data, evt){
                debug(data);
        }
         </script>
     </head>
     <body class="tundra">
    Enter a zip code: <input id="zipcode" type="text" /> <button onclick="getPlace(); return false;" value="Find Place.">Find Place.</button>
      <div>Places:</div><div id="postalCode"></div>
    </body>
</html>

One option is to use the geonames web service that returns locations from zip codes. Here's a quick example of how to use that web service with dojo.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title></title>
        <link rel="stylesheet" type="text/css" href="layout.css">
        <script type="text/javascript">var djConfig = { parseOnLoad: true }</script>
        <script type="text/javascript" src="../dojo-release-1.3.0/dojo/dojo.js"></script>
        </script>
        <script type="text/javascript">
            dojo.require("dojo.io.script");
                function getPlace() {
        var zip = dojo.byId('zipcode').value;
        console.log('zip is ', zip);
        //use country code to get results for a specific country
        //var gn_url = 'http://ws.geonames.org/postalCodeLookupJSON?postalcode=' + zip + '&country=US';
        var gn_url = 'http://ws.geonames.org/postalCodeLookupJSON?postalcode=' + zip;
        console.log(gn_url);
        dojo.io.script.get({
          url: gn_url, 
          callbackParamName: "callback",
          load:function(response, io) { 
            console.log('got json.'); 
            console.dir(response); 
            places = response.postalcodes; 
            var infos = []
            dojo.forEach(places, function(p, i) {
                infos[i] = p.placeName + ', ' + p.adminName1 + ', Lat: ' + p.lat + '; Long: ' + p.lng + '<br />';
            });
                dojo.byId('postalCode').innerHTML = infos.join('');
          }, 
          error:errorCb
        });   
        }

        function errorCb(type, data, evt){
                debug(data);
        }
         </script>
     </head>
     <body class="tundra">
    Enter a zip code: <input id="zipcode" type="text" /> <button onclick="getPlace(); return false;" value="Find Place.">Find Place.</button>
      <div>Places:</div><div id="postalCode"></div>
    </body>
</html>
黎歌 2024-08-02 06:27:43

我不知道有什么方法可以按照您想要的方式与嵌入式 Google 地图进行交互。 最好的选择是使用 Google Maps API 创建您自己的地图。 Google 有一些很棒的文档示例帮助您入门。

I don't know of any way to interact with an embedded Google Map in the way that you want. The best option would be to create your own map with the Google Maps API. Google has some great documentation and examples to get you started.

背叛残局 2024-08-02 06:27:43

嘿,我也在进行类似的搜索。 我在这里找到了有关数学的很好的讨论,以及查询和公式的链接:http:// /uclue.com/?xq=2861。 希望这可以帮助。

hey, i'm working on a similar search too. i found a pretty good discussion of the math involved, as well as links to queries and formulas, here: http://uclue.com/?xq=2861. hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文