The document discusses various Google Maps APIs and techniques, including:
1) Using the Geolocation API to get a user's location and center the map. It discusses handling different browser implementations.
2) Making HTTP requests to retrieve JSON data and parse the response to use in the map.
3) Using the Geocoding API to center the map based on an address.
4) Adding Street View panoramas to a map when visible.
5) Calculating directions between points using the Directions API.
6) Best practices for markers, info windows, and map bounds handling.
15. GeoLocationAPI
GeoLocationAPI
If(navigator.geolocation){//
wid = navigator.geolocation.watchPosition(update);
}
Android
if(!navigator.geolocation) navigator.geolocation = google.gears.factory.create('beta.geolocation');
//
function update(position){
var lat = position.coords.latitude;
var lng = position.coords.longitude;
var currentPos = new google.maps.LatLng(lat, lng);
map.setCenter(currentPos);
//
navigator.geolocation.clearWatch(wid);
}
16. Data Get
var httpObj = createHttpRequest();
httpObj.open("GET",url,true);
httpObj.onreadystatechange = function() {
if (httpObj.readyState == 4 && httpObj.status == 200){
if(httpObj.responseText != ""){
obj = eval("("+httpObj.responseText+")");
}
}
httpObj.send(null);
}
$(function() {
$.getJSON("data.json",function(obj){
hoge(obj);
});
});
17. GeoCoding
//
var gc = new google.maps.Geocoder();
gc.geocode({ address : adrs }, function(results, status){
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
}else{
alert(status+" : ");
}
});
18. StreetView
//
var svp = new google.maps.StreetViewPanorama(
document.getElementById("streetview"), {
position : new google.maps.LatLng(lat,lng)
}
);
if(svp.getVisible()){
map.setStreetView(svp);
}
19. Directions
//
var directionsRenderer = new google.maps.DirectionsRenderer(rendererOptions);
directionsRenderer.setMap(map);
var request = {
origin: point1,
destination: point2,
travelMode: google.maps.DirectionsTravelMode.WALKING
};
var directionsService = new google.maps.DirectionsService();
directionsService.route(request, function(result, status){
if (status == google.maps.DirectionsStatus.OK) {
directionsRenderer.setDirections(result);
}
});
20. Tips
//
function clearOverlays() {
if (markersArray) {
for (i in markersArray) {
markersArray[i].setMap(null);
}
}
}
markersArray.push(marker);
//infoWindow
google.maps.event.addListener(marker, "click", function() {
infowindow = new google.maps.InfoWindow({
content: html
});
if (currentInfoWindow) {
currentInfoWindow.close();
}
infowindow.open(map, marker);
currentInfoWindow = infowindow;
});
21. Tips
Charset
Infowindow
Charset HTML
window.parent.document.f
orm.
V2 V3
23. Tips
//For Client
rc = map.getBounds();
mapArea = rc.getSouthWest() +","+rc.getNorthEast();
var url = "http://hoge/fuga.php?ll="+mapArea+"&cache="+(new Date()).getTime();
var httpObj = createHttpRequest();
httpObj.open("GET",url,true);
httpObj.send(null);
//For Server
$sql = "SELECT * FROM hoge
where ((lat BETWEEN $swlat and $nelat) and (lng BETWEEN $swlng and $nelng))";
NE(lat,lng)
SW(lat,lng)