Examples of how to use Google Maps in flex

Source: Internet
Author: User

First, you need to obtain the Google Maps API key from here.

Download Google Maps ActionScript 3.0 component from here

Next, copy the content in the zip package to the project/libs.

Let's take a look at the demo (Right-click View Source or click here to view the source code):

The following is the complete code (or click here to view details ):

Download: Main. mxml
  1. <? XML version = "1.0" encoding = "UTF-8"?>
  2. <Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml"
  3. Layout = "vertical"
  4. Verticalalign = "Middle"
  5. Backgroundcolor = "white"
  6. Creationcomplete = "Init ();">
  7.  
  8. <Mx: SCRIPT>
  9. <! [CDATA [
  10. Import com. Google. Maps. latlng;
  11. Import com. Google. Maps. Map;
  12. Import com. Google. Maps. mapevent;
  13. Import com. Google. Maps. Controls. maptypecontrol;
  14. Import com. Google. Maps. Controls. positioncontrol;
  15. Import com. Google. Maps. Controls. zoomcontrol;
  16. Import com. Google. Maps. Services. clientgeocoder;
  17. Import com. Google. Maps. Services. geocodingevent;
  18. Import com. Google. Maps. Services. geocodingresponse;
  19. Import com. Google. Maps. Services. placemark;
  20. Import MX. Controls. Alert;
  21. Import MX. Events. resizeevent;
  22.  
  23. Private var GoogleMap: map;
  24. Private var geocoder: clientgeocoder;
  25.  
  26. Private function Init (): void {
  27. GoogleMap = new map ();
  28. GoogleMap. Key = app_id;
  29. GoogleMap. addeventlistener (mapevent. map_ready, googlemap_mapready );
  30. GoogleMap. setsize (new point (mapcontainer. Width, mapcontainer. Height ));
  31. GoogleMap. addcontrol (New zoomcontrol ());
  32. GoogleMap. addcontrol (New maptypecontrol ());
  33.  
  34. Mapcontainer. addchild (GoogleMap );
  35. }
  36.  
  37. Private function geocoder_geocodingsuccess (EVT: geocodingevent): void {
  38. VaR result: placemark = geocodingresponse (EVT. Response). placemarks [0];
  39. GoogleMap. setcenter (result. Point, 13 );
  40. }
  41.  
  42. Private function geocoder_geocodingfailure (EVT: geocodingevent): void {
  43. Alert. Show ("unable to geocode address:" + EVT. Name );
  44. }
  45.  
  46. Private function googlemap_mapready (EVT: mapevent): void {
  47. Geocoder = new clientgeocoder ();
  48. Geocoder. addeventlistener (geocodingevent. geocoding_success, geocoder_geocodingsuccess );
  49. Geocoder. addeventlistener (geocodingevent. geocoding_failure, geocoder_geocodingfailure );
  50. Geocoder. geocode (textinput. Text );
  51. }
  52.  
  53. Private function button_click (EVT: mouseevent): void {
  54. Geocoder. geocode (textinput. Text );
  55. }
  56.  
  57. Private function mapcontainer_resize (EVT: resizeevent): void {
  58. If (GoogleMap ){
  59. GoogleMap. setsize (new point (mapcontainer. Width, mapcontainer. Height ));
  60. }
  61. }
  62. ]>
  63. </MX: SCRIPT>
  64.  
  65. <Mx: String id = "app_id" Source = "appid.txt"/>
  66.  
  67. <Mx: applicationcontrolbar dock = "true">
  68. <Mx: Form stylename = "plain">
  69. <Mx: formitem label = "Address :"
  70. Direction = "horizontal">
  71. <Mx: textinput id = "textinput"
  72. TEXT = "601 Townsend St, San Francisco, CA 94103"/>
  73. <Mx: button id = "button"
  74. Label = "Submit"
  75. Click = "button_click (event);"/>
  76. </MX: formitem>
  77. </MX: Form>
  78. </MX: applicationcontrolbar>
  79.  
  80. <Mx: uicomponent id = "mapcontainer"
  81. Width = "100%"
  82. Height = "100%"
  83. Resize = "mapcontainer_resize (event);"/>
  84.  
  85. </MX: Application>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.