Information Technology Reference
In-Depth Information
case error.PERMISSION_DENIED:
alert ('Geolocation returned permission denied (did you deny
access?)');
break;
case error.UNKNOWN_ERROR:
alert ('Geolocation encountered an unknown error');
break;
}
}
);
}
myLatLong = new google.maps.LatLng(myLatitude, myLongitude);
}
As in the earlier chapter, this uses the navigator.geolocation object of the browser to
determine your latitude and longitude. We'll omit repeating the near-identical code here
to save some space.
We then create a new google.maps.Map object called myTransitMap , placing the center of
the map on our detected location. We set the zoom level to 14 as this is a good scale for
a human on foot, though you can change this to any desired zoom setting. We also
choose the standard road map style of map, rather than satellite view.
TIP: Here are some handy values for zoom level settings to keep in mind when rendering maps
for your users.
Zoom level 12: Suitable for highway-level driving, and showing major routes over tens of miles
or kilometers.
Zoom level 14: Good for inner city driving, and walking directions in general when the distance
is more than a few dozen yards or meters
Zoom level 15: Best for detailed walking, showing building outlines, and driving directions
showing one-way streets and other impediments.
On to our myTransitMap object, we place a marker at the same latitude and longitude
detected for the handset or device. We use our custom blue "You" marker, described
previously, and even provide some hover text to reinforce that this pin places you on the
map.
Lastly, we construct a new local search object, myLocalSearch , and then register the
callback function, processLocalSearchResults() . This will be called when this search
object completes execution of a search. The mechanics of the callback are shown a little
later in this chapter. With the prepareMap() function complete, we can actually see what
our application looks like when the user initially runs it on their device, as shown in
Figure 10-1.
 
Search WWH ::




Custom Search