Google maps 使用谷歌地图API获取企业地址

Google maps 使用谷歌地图API获取企业地址,google-maps,google-maps-api-3,Google Maps,Google Maps Api 3,我有一个要求,我希望谷歌地图API将有一个解决方案。我从来没有使用过谷歌地图API,所以我对这个很陌生 在网站主页上有一个表单,当用户到来时,我希望发生以下事情: 1) 城市字段应填充基于IP的城市用户 2) 还有第二个字段名为store name——当用户开始键入店铺名称时——我想获取该城市中具有该名称的所有业务列表,并将其显示为下拉列表,用户可以从中选择适当的分支机构。没有必要在地图上显示任何东西。 Egs-如果休斯顿的用户开始键入麦当劳,则应开始显示以下商业列表 德克萨斯州休斯顿珍珠大道1

我有一个要求,我希望谷歌地图API将有一个解决方案。我从来没有使用过谷歌地图API,所以我对这个很陌生

在网站主页上有一个表单,当用户到来时,我希望发生以下事情:

1) 城市字段应填充基于IP的城市用户

2) 还有第二个字段名为store name——当用户开始键入店铺名称时——我想获取该城市中具有该名称的所有业务列表,并将其显示为下拉列表,用户可以从中选择适当的分支机构。没有必要在地图上显示任何东西。 Egs-如果休斯顿的用户开始键入麦当劳,则应开始显示以下商业列表

德克萨斯州休斯顿珍珠大道12号麦当劳
  • 德克萨斯州休斯顿巴里区大道2600号麦当劳
  • 德克萨斯州休斯顿克利尔湖大道262号麦当劳
  • 另外,当我们从谷歌API中获取一个商业列表的地址时,我们是将其作为一个字符串来获取并需要对其进行解析,还是将其作为不同的字段(街道名称、城市、州、邮政编码等)来获取

    任何信息或示例都将不胜感激
    谢谢

    我想你不想要谷歌地图。首先,使用条款不允许除在可公开访问的网页上的谷歌地图上显示内容以外的任何其他用途,其次,还有另一个谷歌API,它完全满足您的需要:客户端位置API:

    关于“商业”:你必须从某处获取数据——我不相信谷歌有这方面的服务。也许您可以简单地使用Google搜索API和一些逻辑来只查找企业()


    编辑:对于企业,也许您可以看看这个示例:

    更新:下面是一个使用jsonp使用和本地搜索的示例


    
    功能$g(id){
    返回文档.getElementById(id);
    }
    功能显示位置(latitudeEl、Longtudeel、cityEl、regionEl、countryEl、country_codeEl){
    var cloc=newclientlocation.Location(google.loader.ClientLocation);
    如果(latitudeEl)latitudeEl.innerHTML=cloc.latitude;
    如果(longitudeEl)longitudeEl.innerHTML=cloc.longitude;
    如果(cityEl)cityEl.innerHTML=cloc.address.city;
    如果(regionEl)regionEl.innerHTML=cloc.address.region;
    如果(country)country.innerHTML=cloc.address.country;
    如果(country_codeEl)country_codeEl.innerHTML=cloc.address.country_代码;
    }
    函数localSearch(术语、回调、上下文){
    var cloc=newclientlocation.Location(google.loader.ClientLocation);
    var searchUrl=http://www.google.com/uds/GlocalSearch?callback=“+callback+”&context=“+context+”&hl=en&q=“+encodeURIComponent(term)+”&sll=“+cloc.latitude+”、“+cloc.longitude+”&key=abqiaaaldwetdqhojcbcff0jnuql8bt2yxp_ZAY8_ufc3cfxhie1nvwkxqa7ae8sb9mywghecpy2qimop7buq&v=1.0”;
    // http://jaybyjayfresh.com/2007/09/17/using-script-tags-to-do-remote-http-calls-in-javascript/
    scriptLoaded=函数(){
    removeNode(newScript);
    };
    var headID=document.getElementsByTagName(“head”)[0];
    var newScript=document.createElement('script');
    newScript.type='text/javascript';
    newScript.onload=scriptLoaded;
    newScript.src=搜索URL;
    headID.appendChild(newScript);
    }
    函数搜索(){
    var术语=$g(“txtSearch”).值;
    本地搜索(术语“显示结果”、“0”);
    }
    函数displayResults(上下文、结果、状态、详细信息、未使用){
    var标题=[];
    对于(var i=0;i”);
    }
    函数init(){
    显示位置($g(“纬度”)、$g(“经度”)、$g(“城市”)、$g(“地区”)、$g(“国家”)、$g(“国家代码”);
    }
    纬度:
    
    经度:
    城市:
    地区:
    国家:
    国家/地区代码:


    //
    //此源位于公共域中。
    // http://skysanders.net/subtext
    //感谢归因。
    // 
    /*
    google.loader.clientlocation的对象文字格式
    {
    “纬度”:33.324,
    “经度”:-111.867,
    “地址”:{
    “城市”:“钱德勒”,
    “区域”:“AZ”,
    “国家”:“美国”,
    “国家/地区代码”:“美国”
    }
    }
    */
    var ClientLocation={};
    ClientLocation.Address=函数(){
    /// 
    /// 
    /// 
    /// 
    /// 
    如果(arguments.length>0){
    this.city=参数[0]。城市;
    this.region=参数[0]。region;
    this.country=参数[0]。国家;
    this.country\u code=参数[0]。country\u code;
    返回;
    }
    否则{
    this.city=“”;
    this.region=“”;
    this.country=“”;
    this.country_code=“”;
    }
    }
    ClientLocation.Location=函数(){
    /// 
    /// 
    /// 
    如果(arguments.length>0){
    this.latitude=参数[0]。latitude;
    this.longide=参数[0]。经度;
    this.address=参数[0]。地址;
    }
    否则{
    这个纬度=0;
    这个经度=0;
    this.address=未定义;
    }
    }
    // 
    //此源位于公共域中。
    // http://skysanders.net/subtext
    //感谢归因。
    // 
    /*
    GlocalSearch结果
    {
    “GsearchResultClass”:“GlocalSearch”,
    “视口模式”:“已计算”
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    
        <script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAALDWeTDQHOJCbCf0JnUqL8BT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQA7AE8xB9MyWgHECPY2qimOp7BUQ"></script>
    
        <script src="scripts/clientLocation.js" type="text/javascript"></script>
    
        <script src="scripts/localSearch.js" type="text/javascript"></script>
    
        <script type="text/javascript">
    
    
    
            function $g(id) {
                return document.getElementById(id);
            }
    
            function displayLocation(latitudeEl, longitudeEl, cityEl, regionEl, countryEl, country_codeEl) {
                var cloc = new ClientLocation.Location(google.loader.ClientLocation);
                if (latitudeEl) latitudeEl.innerHTML = cloc.latitude;
                if (longitudeEl) longitudeEl.innerHTML = cloc.longitude;
                if (cityEl) cityEl.innerHTML = cloc.address.city;
                if (regionEl) regionEl.innerHTML = cloc.address.region;
                if (country) country.innerHTML = cloc.address.country;
                if (country_codeEl) country_codeEl.innerHTML = cloc.address.country_code;
            }
            function localSearch(term, callback, context) {
                var cloc = new ClientLocation.Location(google.loader.ClientLocation);
                var searchUrl = 'http://www.google.com/uds/GlocalSearch?callback=' + callback + '&context=' + context + '&hl=en&q=' + encodeURIComponent(term) + '&sll=' + cloc.latitude + ',' + cloc.longitude + '&key=ABQIAAAALDWeTDQHOJCbCf0JnUqL8BT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQA7AE8xB9MyWgHECPY2qimOp7BUQ&v=1.0';
    
                // http://jaybyjayfresh.com/2007/09/17/using-script-tags-to-do-remote-http-calls-in-javascript/
                scriptLoaded = function() {
                    removeNode(newScript);
                };
    
                var headID = document.getElementsByTagName("head")[0];
                var newScript = document.createElement('script');
                newScript.type = 'text/javascript';
                newScript.onload = scriptLoaded;
                newScript.src = searchUrl;
                headID.appendChild(newScript);
            }
            function search() {
                var term = $g("txtSearch").value;
                localSearch(term, "displayResults", "0");
    
            }
            function displayResults(context, results, status, details, unused) {
                var titles = [];
                for (var i = 0; i < results.results.length; i++) {
                    // this cast is not necessary, just here to illustrate
                    // vs intellisense and reduce coding errors.
                    var result = new LocalSearch.Result(results.results[i]);
                    titles.push(result.title);
                }
                $g("searchResults").innerHTML = titles.join("</br>");
            }
            function init() {
    
                displayLocation($g("latitude"), $g("longitude"), $g("city"), $g("region"), $g("country"), $g("country_code"));
            }
        </script>
    
    </head>
    <body onload="init()">
        <form id="form1" runat="server">
        <div>
            latitude : <span id="latitude"></span>
            <br />
            longitude : <span id="longitude"></span>
            <br />
            city : <span id="city"></span>
            <br />
            region : <span id="region"></span>
            <br />
            country : <span id="country"></span>
            <br />
            country_code : <span id="country_code"></span>
            <br />
        </div>
        <input type="text" id="txtSearch" /><input type="button" id="btnSearch" value="get results"
            onclick="search();" /><br />
        &nbsp;<div id="searchResults">
        </div>
        </form>
    </body>
    </html>
    
    // <copyright file="clientLocation.js" company="Sky Sanders">
    // This source is placed in the Public Domain.
    // http://skysanders.net/subtext
    // Attribution is appreciated.
    // </copyright>
    
    
    /*
    object literal format for google.loader.clientlocation  
    {
    "latitude": 33.324,
    "longitude": -111.867,
    "address": {
    "city": "Chandler",
    "region": "AZ",
    "country": "USA",
    "country_code": "US"
    }
    }
    */
    
    var ClientLocation = {};
    
    ClientLocation.Address = function() {
        /// <field name="city" type="String" />
        /// <field name="region" type="String" />
        /// <field name="country" type="String" />
        /// <field name="country_code" type="String" />
        /// <returns type="ClientLocation.Address"/>
        if (arguments.length > 0) {
            this.city = arguments[0].city;
            this.region = arguments[0].region;
            this.country = arguments[0].country;
            this.country_code = arguments[0].country_code;
            return;
        }
        else {
            this.city = "";
            this.region = "";
            this.country = "";
            this.country_code = "";
        }
    
    }
    ClientLocation.Location = function() {
        /// <field name="latitude" type="Number" />
        /// <field name="longitude" type="Number" />
        /// <field name="address" type="ClientLocation.Address" />
        if (arguments.length > 0) {
    
            this.latitude = arguments[0].latitude;
            this.longitude = arguments[0].longitude;
            this.address = arguments[0].address;
    
        }
        else {
            this.latitude = 0;
            this.longitude = 0;
            this.address = undefined;
        }
    
    }
    
    
    // <copyright file="localSearc.js" company="Sky Sanders">
    // This source is placed in the Public Domain.
    // http://skysanders.net/subtext
    // Attribution is appreciated.
    // </copyright>
    /*
    GlocalSearch result
    
    {
    "GsearchResultClass": "GlocalSearch",
    "viewportmode": "computed",
    "listingType": "local",
    "lat": "33.389689",
    "lng": "-111.853909",
    "accuracy": "8",
    "title": "Best \u003cb\u003eBuy\u003c/b\u003e",
    "titleNoFormatting": "Best Buy",
    "ddUrl": "http://www.google.com/maps....",
    "ddUrlToHere": "http://www.google.com/maps?....",
    "ddUrlFromHere": "http://www.google.com/maps?....",
    "streetAddress": "1337 South Alma School Road",
    "city": "Mesa",
    "region": "AZ",
    "country": "United States",
    "staticMapUrl": "http://mt.google.com/mapdata?....",
    "url": "http://www.google.com/maps/place?source....",
    "content": "",
    "maxAge": 604800,
    "phoneNumbers": [{
    "type": "",
    "number": "(480) 644-7139"
    },
    {
    "type": "",
    "number": "(480) 464-0444"
    }],
    "addressLines": ["1337 South Alma School Road", "Mesa, AZ"]
    }
    
    */
    
    
    var LocalSearch = {};
    
    LocalSearch.PhoneNumber = function() {
        /// <field name="type" type="String"/>
        /// <field name="number" type="String"/>
        /// <returns type="LocalSearch.PhoneNumber"/>
    
        if (arguments.length > 0) {
            this.type = arguments[0].type;
            this.number = arguments[0].number;
        }
        else {
            this.type = "";
            this.number = "";
        }
    }
    
    
    
    LocalSearch.Result = function() {
        /// <field name="GsearchResultClass" type="String"/>
        /// <field name="viewportmode" type="String"/>
        /// <field name="listingType" type="String"/>
        /// <field name="lat" type="String"/>
        /// <field name="lng" type="String"/>
        /// <field name="accuracy" type="String"/>
        /// <field name="title" type="String"/>
        /// <field name="titleNoFormatting" type="String"/>
        /// <field name="ddUrl" type="String"/>
        /// <field name="ddUrlToHere" type="String"/>
        /// <field name="ddUrlFromHere" type="String"/>
        /// <field name="streetAddress" type="String"/>
        /// <field name="city" type="String"/>
        /// <field name="region" type="String"/>
        /// <field name="country" type="String"/>
        /// <field name="staticMapUrl" type="String"/>
        /// <field name="url" type="String"/>
        /// <field name="content" type="String"/>
        /// <field name="maxAge" type="Number"/>
        /// <field name="phoneNumbers" type="Array"/>
        /// <field name="addressLines" type="Array"/>
        // <returns type="LocalSearch.Result"/>
        if (arguments.length > 0) {
            this.GsearchResultClass = arguments[0].GsearchResultClass;
            this.viewportmode = arguments[0].viewportmode;
            this.listingType = arguments[0].listingType;
            this.lat = arguments[0].lat;
            this.lng = arguments[0].lng;
            this.accuracy = arguments[0].accuracy;
            this.title = arguments[0].title;
            this.titleNoFormatting = arguments[0].titleNoFormatting;
            this.ddUrl = arguments[0].ddUrl;
            this.ddUrlToHere = arguments[0].ddUrlToHere;
            this.ddUrlFromHere = arguments[0].ddUrlFromHere;
            this.streetAddress = arguments[0].streetAddress;
            this.city = arguments[0].city;
            this.region = arguments[0].region;
            this.country = arguments[0].country;
            this.staticMapUrl = arguments[0].staticMapUrl;
            this.url = arguments[0].url;
            this.content = arguments[0].content;
            this.maxAge = arguments[0].maxAge;
            this.phoneNumbers = arguments[0].phoneNumbers;
            this.addressLines = arguments[0].addressLines;
    
        }
        else {
    
            this.GsearchResultClass = "";
            this.viewportmode = "";
            this.listingType = "";
            this.lat = "";
            this.lng = "";
            this.accuracy = "";
            this.title = "";
            this.titleNoFormatting = "";
            this.ddUrl = "";
            this.ddUrlToHere = "";
            this.ddUrlFromHere = "";
            this.streetAddress = "";
            this.city = "";
            this.region = "";
            this.country = "";
            this.staticMapUrl = "";
            this.url = "";
            this.content = "";
            this.maxAge = 0;
            this.phoneNumbers = [];
            this.addressLines = [];
        }
    
    
    }