Preview only show first 10 pages with watermark. For full document please download
Progetto Simple Mobile Services: Realizzazione Di
-
Rating
-
Date
November 2018 -
Size
1.8MB -
Views
9,414 -
Categories
Transcript
Università degli studi di Roma “Tor Vergata” Facoltà di Ingegneria Corso di Laurea Triennale in Ingegneria Informatica Tesi di Laurea Progetto Simple Mobile Services: realizzazione di un proxy verso servizi di mappe e localizzazione geografica Relatore: Ing. Stefano D. Salsano Laureando: Alessio Bianchi Anno accademico 2007-2008 Sessione di aprile Licensed under Creative Commons License “Attribution – Share alike” 2.5 Alessio Bianchi) phone => Snippet[1] (second token obtained after splitting Snippet around
) lat => Point->coordinates[0] (first token obtained after splitting Point->coordinates around the comma) lon => Point->coordinates[0] (second token obtained after splitting Point->coordinates around the comma) Each of these arrays is then pushed in the results array. The function then returns a new BusinessResultset object containing the results array, and whose __toString() method is automatically invoked when the caller function search() echoes the object to the standard output. An example of the structure of the resultset array incapsulated into the BusinessResultset object is available in code 3.14. If the address is ambiguous, the function returns a new AddressResultset object containing the array of choices got from the address search. Route calculation Route calculation does not offer explicit error notification as well. So, both the source and the destination address have to be checked for ambiguity by doing a preliminar address_search() on them. If one of them is ambiguous, the list of choices got from the address search is encapsulated into an AddressResultset, and the $additionaldata parameter of its constructor is set either to OPTsaddr or to OPTdaddr, depending on which address 3.5 Implementation 41 1 Array 2 ( 3 [0] => Array 4 ( 5 [name] => Baldi 6 [address] => Via Del Leoncino, 28, 00186 Roma (RM), Italy 7 [phone] => 06 6867757 8 [lat] => 12.478076 9 [lon] => 41.904383 10 ) 11 12 [1] => Array 13 ( 14 [name] => Appia Nuova 2003 S.R.L. 15 [address] => Via Della Mercede, 45, 00187 Roma (RM), Italy 16 [phone] => 06 6786015 17 [lat] => 12.482035 18 [lon] => 41.903237 19 ) 20 ) Code 3.14: Results array for businesses, obtained by the PHP’s function print_r. is ambiguous. For a description on how this data field is used when assembling response, refer to section 3.3.3. The sequence diagram 3.5 shows the interaction with the MOVE client when both the addresses are ambiguous. If both the addresses are not ambiguous, the XML response is parsed and iterated over Document->Placemark. The associative array containing each result is assembled as an associative array with the following structure: direction => name distance => description lat => Point->coordinates[0] (first token obtained after splitting Point->coordinates around the comma) lon => Point->coordinates[0] (second token obtained after splitting Point->coordinates around the comma) For each iteration, $center_lat, $center_lon, $span_lat and $span_lon are updated. Finally, a RouteResultset object containing an array which, in turn, contains the array of directions, $center_lat, $center_lon, $span_lat and $span_lon is returned. An example of the structure of the resultset array incapsulated into the RouteResultset object is available in code 3.15. 3.5 Implementation 1 Array 2 ( 3 [steps] => Array 4 ( 5 [0] => Array 6 ( 7 [direction] => Head south on Via del Corso toward Via in Lucina 8 [distance] => 0.2 km 9 [lat] => 12.479480 10 [lon] => 41.903200 11 ) 12 13 [1] => Array 14 ( 15 [direction] => Turn left at Largo Chigi 16 [distance] => 87 m 17 [lat] => 12.480190 18 [lon] => 41.901540 19 ) 20 21 [2] => Array 22 ( 23 [direction] => Continue on Via del Tritone 24 [distance] => 0.3 km 25 [lat] => 12.481190 26 [lon] => 41.901780 27 ) 28 29 [3] => Array 30 ( 31 [direction] => Arrive at: Via del Tritone, 00187 Rome RM, Italy 32 [distance] => 33 [lat] => 12.484100 34 [lon] => 41.902470 35 ) 36 37 ) 38 39 [center_lat] => 12.48179 40 [center_lon] => 41.90237 41 [span_lat] => 0.0023099999999996 42 [span_lon] => 0.00083000000000055 43 ) Code 3.15: Results array for waypoints, obtained by the PHP’s function print_r. 42 3.5 Implementation 43 Map tile retrieval First of all, the provider-specific local cache directory for maptiles is read from the configuration file, and it is checked whether the web server has permissions to write in it. Then, it is checked whether the requested maptile is available in cache: if yes it is loaded and sent directly to the MOVE client, otherwise a request to Google Maps is made and the downloaded maptile is stored into the cache. It is important to notice that, in such requests, at least the user-agent must be submitted as header, otherwise Google will not serve the request. The downloadToFile function is used to download the file directly to mass storage. 3.5.4 The Yahoo Maps map provider Address search As specified in table 3.2, Yahoo Maps only offers address search. Unlike Google Maps, the return code is not provided inside the XML response data, but it is actually the HTTP response code. For this reason, to download the resource, it is necessary to use the download_with_response() function, which returns an associative array containing the response code under the key serverResponse and the actual resource under the key fileContent. The meaning of error codes is like standard HTTP’s: 200 if the request was processed successfully, 400 in case of errors. Once got the XML, it is parsed via SimpleXML and iterated over Result nodes. Each result is then assembled as an associative array with the following structure: address => combination of Address, City, State as in “Via del Corso, 00186 Rome RM Italy” (see next section 3.5.5 for details) lat => Latitude lon => Longitude Each of these arrays is pushed into the results array, which will be encapsulated into an AddressResultset object and returned by the function. Map tile retrieval Yahoo Maps’ map tile retrieval is practically identical to Google Maps’ (see section 3.5.3. 3.5.5 The MSN Live Local map provider Business search Unlike the other two map providers previously examined, MSN Live Local does not offer any XML-based solution for automatic querying. The implementation of business search of the previous solution has then been taken nearly unaltered. 3.5 Implementation 44 Once received the XHTML code of the response, a regular expression checks whether results were found by testing for the absence of a div whose id is NoResultsControl. If there are results, geographic coordinates are extracted by splitting the text after the token mapLatLongs around the comma. The business name and the phone number are then extracted from the text arounf the token . These pieces of data are assembled into associative arrays, which are, in turn, assembled into the results array. This is encapsulated into a BusinessResultset and returned by the function. Notice that this method has no error checking or recovery, as is is not possible to discriminate errors based on the output format received. Hence, detectable errors such as ambiguous address or map provider issues are reported to the MOVE client as a generic error. Map tile retrieval MSN Live Local’s map tile retrieval is practically identical to Google Maps’ (see section 3.5.3. 3.5.6 The Automatic map provider Address search Having written address search methods using exceptions and a separate object to assemble the response, writing a Google Maps address search with automatic fallback to Yahoo Maps is quite easy, as reported in code 3.16. 1 public function address_search($place) 2 { 3 try 4 { 5 return $this->google->address_search($place); 6 } 7 catch (MapProviderException $mpe1) 8 { 9 return $this->yahoo->address_search($place); 10 } 11 } Code 3.16: Address search with automatic fallback. This way, if GoogleMaps::address_search() throws an exception, the same request is made again by invoking YahooMaps::address_search(). If even Yahoo Maps throws an exception, this it is not caught and rather forwarded to the caller, namely the search() function, which catches it and calls the error handling function. The same considerations about response assembly using AddressResultset objects made before apply here as well. 3.5 Implementation 45 Business search Business search with automatic fallback (see code 3.17) makes the business search request to Google Maps. If an exception is thrown, it is caught and the fallback mechanism starts. Recall that the only other map provider offering business search capability is MSN Live Local which, though, requires a very precise address as input. This address is obtained by invoking Yahoo Maps’ address search, and formatting the geocoded address the way MSN expects it to be. Notice that if Yahoo Maps’ address search fails, the business search request toward MSN is made anyway using the user-entered address3 . 1 public function business_search($what, $near) 2 { 3 try 4 { 5 return $this->google->business_search($what, $near); 6 } 7 catch (MapProviderException $mpe1) 8 { 9 try 10 { 11 $results = $this->yahoo->address_search($near); 12 if (count($results->resultset) == 1) 13 { 14 $near = urlencode($results->resultset[0][’address’]); 15 } 16 else 17 { 18 return $results; // address is ambiguous: send options back to MOVE client 19 } 20 } 21 catch (MapProviderException $mpe) 22 { 23 /* 24 * It is not compulsory to do geocoding with Yahoo in order to do a 25 * business search with MSN, so we don’t abort here, but continue. 26 * However, it is highly probable that MSN won’t recognize the 27 * address, especially if it is written liberally ("via del tritone, 28 * roma" VS "Via del Tritone, 00187 Roma RM, Italy") 29 */ 30 } 31 return $this->msn->business_search($what, $near); 32 } 33 } Code 3.17: Business search with automatic fallback. 3 This, as seen, will most probably fail. . . 3.6 Integration in the MOVE client 46 Route calculation No map provider other than Google Maps offers route calculations, so this method merely invokes GoogleMaps::route_search(). Map tile retrieval Map tile retrieval with automatic fallback uses the same concept seen above: if a map provider throws an exception, use the next one. Nothing fancy has to be said about the code, reported in code 3.18. 1 public function get_map_tile($location) 2 { 3 try 4 { 5 $this->google->get_map_tile($location); 6 } 7 catch (NetworkProblemException $npe) 8 { 9 try 10 { 11 $this->yahoo->get_map_tile($location); 12 } 13 catch (NetworkProblemException $npe) 14 { 15 $this->msn->get_map_tile($location); 16 } 17 } 18 } Code 3.18: Map tile retrieval with automatic fallback. 3.6 Integration in the MOVE client This section explains the changes that have been made to the MOVE client code. This work has been done on MOVE client 1.04 alpha 03, and then integrated, among changes in other portions, in the ‘trunk’ branch. The source code can be downloaded from http://minerva.netgroup.uniroma2.it/sms. 3.6.1 navigator/smsnavigator/MapTileManager.java The MapTileManager class contains map tile management logic. The only modified function is download(). It is used to retrieve the maptile image corresponding to the MapTile object passed as parameter by making an appropriate request to SMSNavigatorProxy. During construction of the URL to use to retrieve the maptile, the chosen map provider saved in Navigator’s preferences (the setting named mapsEngine) is checked. This is done in order to add to the GET method of 3.6 Integration in the MOVE client 47 the request the correct set of coordinate variables only: gx-gy-gz if mapsEngine is Google Maps, yx-yy-yz if it is Yahoo Maps, mr if it is MSN Maps, all of the above if it is Auto. 3.6.2 navigator/smsnavigator/PrefsEditor.java This class is a form which allows the user to set certain preferences for the Navigator, among which the map provider to be used. A new item for the Automatic map provider has been added in the combo box containing map provider possible choices. This has been accomplished by modifying the getMapsEngineArray() function. The getIndexMapsEnginePreference() function, which returns an integer corresponding to the map provider in use, has also been modified to give a correct result when the Automatic map provider is chosen. 3.6.3 navigator/smsnavigator/SearchMenu.java This class deals with request/response handling of the three search types. Support for selectable map provider has been added: the submitSearch() has been modified to include the GET variable provider to the request and to set its value to the current provider in use. Compliance with the new route search response format (see section 3.3.2) has been introduced. In function submitSearch(), the polyline decoding code block has been removed and the parsing and extraction of waypoint coordinates has been joined to address search’s and business search’s, as the three formats are now identical. Address ambiguity management for route searches has been also updated. For more details, refer to section 3.3.3. Chapter 4 Future developments and conclusions Section 4.1 contains some proposals for future enhancements and guidelines about how to implement a new map provider. Section 4.2 focuses on the overall accomplishments obtained at the end of this thesis work. 4.1 Future developments The most effective extension that can be made in the near future is the implementation of new map providers. As ease of expansion was one of the design goals, adding new map providers is a relatively easy task. The following guidelines should be followed: 1. Create a MyProvider class, which extends the MapProvider class, inside the new file MyProvider.class.php. As seen, thanks to the use of a factory method to instantiate provider objects and PHP’s dynamic class loading, nothing more has to be changed to use the new map provider: it is enough to specify it as the value of the provider GET variable in the request. 2. Redefine abstract methods address_search, business_search, route_search and get_map_tile. If the map provider does not support one of these search types, or you want to make it unavailable for any reason, redefine the corresponding method to throw a ServiceUnavailable exception. 3. Inside these methods, assemble the raw data extracted from the map provider’s response (address, coordinates, etc.) as one of the appropriate arrays, which are here summarized for the reader’s convenience: Results array for addresses Contains one associative array per result. Each associative array must use the keys address, lat, lon. For an example, refer to code 3.13 on page 40. 4.2 Conclusions 49 Results array for businesses Contains one associative array per result. Each associative array must use the keys name, address, phone, lat, lon. For an example, refer to code 3.14 on page 41. Results array for waypoints Contains: • a steps associative array which, in turn, contains one associative array per waypoint. Each waypoint array must use the keys direction, distance, lat, lon • a center_lat entry • a center_lon entry • a span_lat entry • a span_lon entry For an example, refer to code 3.15 on page 42. 4. Do not return the results array of the previous point directly but, instead, return a freshly created AddressResultset, BusinessResultset or RouteResultset object containing those results. This will ensure that the response format will be parsable my the MOVE client. 5. If you want to provide cached map tile retrieval, add a new option to the smsnavigator.conf.php configuration file, specifying the absolute or relative path of the cache directory to use for your provider’s maptiles. 6. Your search methods should use the declared exceptions in order to notify errors to the MOVE client in a consistent manner with respect to other map providers. 7. You may want to use the functions available in the file smsnavigator.conf.php to download a file. 4.2 Conclusions At the end of this thesis work, the improvements carried out to SMSNavigatorProxy with respect to the previous solution are several: • Data retrieval from map providers has been stabilized by using XML and, so, decoupled from changes in the presentation HTML code. MSN Live Local is the only provider which still uses the old approach of extracting data from pages by regular expressions, because it does not offer XML support. • The structure of SMSNavigatorProxy has been redesigned from scratch, in order to allow the most painless possible future expansion by adding, as explained in the previous section, new map providers and other features. 4.2 Conclusions 50 • The request format has been extended and streamlined, by reorganizing GET variables name and meaning. For example, the current variable address is the result of merging the two variables near and q of the old solution. • The route search response protocol and the corresponding portions of the MOVE client have also been greatly simplified by the elimination of the polyline and its related decoding and management. Appendix A Map services output examples In this appendix, examples of the XML code returned by the map providers supporting it is returned. A.1 Google Maps A.1.1 Address search KML geocoding output for “via del politecnico, roma”. 1 2
200
7 Business listings provided by PagineGialle.it]]> 9