2. Use the custom JS and gclientgeocoder classes in the Google map API
In fact, the Google map API provides a gclientgeocoder class to implement address decoding, that is, to convert place names and coordinates. This is to submit the place names from the client to find the database and return the coordinates.
Let's take a look at the following code:
VaR rpoint;
VaR map = new gmap2 (document. getelementbyid ("gmapcontainer "));
VaR geocoder = new gclientgeocoder ();
Geocoder. getlatlng (STR, function (rpoint ){
// Alert (STR );
If (! Rpoint ){
Alert (STR + "unable to parse address ");
}
Else {
// Alert (rpoint );
Map. setcenter (rpoint, 15 );
VaR marker = new gmarker (rpoint );
Map. addoverlay (Marker );
Marker. openinfowindowhtml ("Welcome to view" + STR + "map ");
Map. enabledoubleclickzoom ();
Map. enablescrollwheelzoom ();
Map. enablecontinuouszoom ();
Map. addcontrol (New glargemapcontrol ())
Map. addcontrol (New goverviewmapcontrol ());
Map. addcontrol (New gscalecontrol ());
Map. addcontrol (New gmaptypecontrol ());
New gkeyboardhandler (MAP );
// Map. enablegooglebar ();
}
});
From the code above, we can see that geocoder is an instance of the gclientgeocoder class.
Geocoder. getlatlng (STR, function );
To obtain the geographical coordinate value corresponding to the place name STR, and then display the map through the map object of the gmap2. From this we can see that using a custom method requires two Google map queries on the server. Of course, in terms of efficiency, it is not as good as googlebar or googlebar, but in some occasions, it is still necessary.
Example:Myapp2.html.
(End of this series)