对于 #2,您可以创建仅包含“已加星标”的宠物友好餐厅的自定义地图,并使用您的地图 ID 让其他人看到它。像这张地图的东西:
对于 #1 和 #3,您可以使用 Google Places API:
https ://developers.google.com/maps/documentation/javascript/examples/place-radar-search
这是一个使用 Google Places 中的数据搜索“狗餐厅”的示例。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Search for up to 200 places with Radar Search</title>
<link href="http://developers.google.com/maps/documentation/javascript/examples/default.css" rel="stylesheet">
<script src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places,visualization&v=3.exp"></script>
<script>
var map;
var infoWindow;
var service;
function initialize() {
map = new google.maps.Map(document.getElementById('map-canvas'), {
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: new google.maps.LatLng(-33.8668283734, 151.2064891821),
zoom: 15,
styles: [
{
stylers: [
{ visibility: 'simplified' }
]
},
{
elementType: 'labels',
stylers: [
{ visibility: 'off' }
]
}
]
});
infoWindow = new google.maps.InfoWindow();
service = new google.maps.places.PlacesService(map);
google.maps.event.addListenerOnce(map, 'bounds_changed', performSearch);
document.forms.kwForm.onsubmit = performSearch;
}
function performSearch() {
var request = {
bounds: map.getBounds(),
keyword: document.forms.kwForm.keywords.value // 'dog restaurant'
};
service.radarSearch(request, callback);
return false;
}
function callback(results, status) {
if (status != google.maps.places.PlacesServiceStatus.OK) {
alert(status);
return;
}
for (var i = 0, result; result = results[i]; i++) {
createMarker(result);
}
}
function createMarker(place) {
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location,
icon: {
// Star
path: 'M 0,-24 6,-7 24,-7 10,4 15,21 0,11 -15,21 -10,4 -24,-7 -6,-7 z',
fillColor: '#ffff00',
fillOpacity: 1,
scale: 1/4,
strokeColor: '#bd8d2c',
strokeWeight: 1
}
});
google.maps.event.addListener(marker, 'click', function() {
service.getDetails(place, function(result, status) {
if (status != google.maps.places.PlacesServiceStatus.OK) {
alert(status);
return;
}
infoWindow.setContent(result.name);
infoWindow.open(map, marker);
});
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas" style="width:80%; height:90%; "></div>
<form id="kwForm">
<input type=text value="dog restaurant" name="keywords" id="keywords" />
<input type=submit />
</form>
</body>
</html>
现在您需要做的就是使用地理位置跟踪您的位置:
navigator.geolocation.watchPosition
并添加一些 jQuery Mobile 代码,你就有了一个可以工作的应用程序。
如果您想将所有对狗友好的位置导入您自己的数据库,也可以使用嵌入在地图中的 Google Fusion Tables 。