距离我最近的修车店 (距离我最近的菜鸟驿站)

武汉桑拿 04-13 阅读:47 评论:0
距离我最近的修车店 (距离我最近的菜鸟驿站)

修车店

  1. 店名 1

    地址:地址 1

    电话:电话号码 1

    距离:距离 1

  2. 店名 2

    地址:地址 2

    电话:电话号码 2

    距离:距离2

  3. 店名 3

    地址:地址 3

    电话:电话号码 3

    距离:距离 3

菜鸟驿站

  1. 驿站名 1

    地址:地址 1

    电话:电话号码 1

    距离:距离 1

  2. 驿站名 2

    地址:地址 2

    电话:电话号码 2

    距离:距离 2

  3. 驿站名 3

    地址:地址 3

    电话:电话号码 3

    距离:距离 3

style.css css body {font-family: Arial, Helvetica, sans-serif; }h1 {font-size: 24px;margin-bottom: 10px; }h2 {font-size: 20px;margin-bottom: 10px; }ol {list-style-type: none;padding: 0; }li {margin-bottom: 10px; }a {color: 000;text-decoration: none; }p {font-size: 14px;margin-bottom: 5px; }script.js js (function() {// Get the user's current locationnavigator.geolocation.getCurrentPosition(function(position) {var latitude = position.coords.latitude;var longitude = position.coords.longitude;// Use the Places API to find nearby repair shops and CaiNiao stationsvar request = {location: {lat: latitude,lng: longitude},radius: '500',query: '修车店'};var service = new google.maps.places.PlacesService(document.createElement('div'));service.textSearch(request, function(results, status) {if (status === google.maps.places.PlacesServiceStatus.OK) {for (var i = 0; i < results.length; i++) {var result = results[i];// Add the repair shop to the listvar li = document.createElement('li');var a = document.createElement('a');a.href = result.url;a.textContent = result.name;li.appendChild(a);var p = document.createElement('p');p.textContent = '地址:' + result.formatted_address;li.appendChild(p);p = document.createElement('p');p.textContent = '电话:' + result.formatted_phone_number;li.appendChild(p);p = document.createElement('p');p.textContent = '距离:' + result.distance + ' 米';li.appendChild(p);document.getElementById('repair-shops').appendChild(li);}}});// Do the same thing for CaiNiao stationsrequest.query = '菜鸟驿站';service.textSearch(request, function(results, status) {if (status === google.maps.places.PlacesServiceStatus.OK) {for (var i = 0; i < results.length; i++) {var result = results[i];// Add the CaiNiao station to the listvar li = document.createElement('li');var a = document.createElement('a');a.href = result.url;a.textContent = result.name;li.appendChild(a);var p = document.createElement('p');p.textContent = '地址:' + result.formatted_address;li.appendChild(p);p = document.createElement('p');p.textContent = '电话:' + result.formatted_phone_number;li.appendChild(p);p = document.createElement('p');p.textContent = '距离:' + result.distance + ' 米';li.appendChild(p);document.getElementById('cainiao-stations').appendChild(li);}}});}); })();
版权声明

本文仅代表作者观点,不代表武汉桑拿立场。
本文系作者授权发表,未经许可,不得转载。