The framework provides MapKit many useful features, except the return of Longitude and Latitude from an address. In JavaScript, for example, you can use the service provided by Google Geocoding and discussed in Google Maps: How to get Latitude and Longitude from an address . Apple iPhone or iPad, however, you can overcome this obstacle by using a different Google services. Specifically, you can call directly to the url:
1
| http://maps.google.com/maps/geo?q = [address] & output = csv |
Where is [indirizzo] to enter the string with the address you want to transform coordinates. The output returned is of type:
1
| 200,8,41.9128300,12.2241172 |
). The first value, 200 , indicates that everything went well ( 200 OK ). The second, 8 , Google is the accuracy parameter (1-10). The last two values are, finally, latitude and longitude. Now we see a prototype of a method can be included in our applications:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| CLLocationCoordinate2D ) getLocationFromAddress : ( NSString * ) address { - (CLLocationCoordinate2D) getLocationFromAddress: ( NSString *) address { urlString = [ NSString stringWithFormat : @ "http://maps.google.com/maps/geo?q=%@&output=csv" , NSString * urlString = [ NSString stringWithFormat: @ "% @ http://maps.google.com/maps/geo?q = & output = csv" NSUTF8StringEncoding ] ] ; [StringByAddingPercentEscapesUsingEncoding address: NSUTF8StringEncoding]]; listItems = [ locationString componentsSeparatedByString : @ "," ] ; NSArray * ListItems = [locationString componentsSeparatedByString: @ ""]; / / Int zoom = 0; 0.0 ; double latitude = 0.0; 0.0 ; double longitude = 0.0; listItems count ] > = 4 && [ [ listItems objectAtIndex : 0 ] isEqualToString : @ "200" ] ) { if ([ListItems count]> = 4 & & [[ListItems objectAtIndex: 0] isEqualToString: @ "200"]) { / / Zoom = [[ListItems objectAtIndex: 1] intValue]; listItems objectAtIndex : 2 ] doubleValue ] ; Latitude = [[ListItems objectAtIndex: 2] doubleValue]; listItems objectAtIndex : 3 ] doubleValue ] ; longitude = [[ListItems objectAtIndex: 3] doubleValue]; { Else {} / / Error } CLLocationCoordinate2D location; location.latitude = latitude; location.longitude = longitude; return location; } |
Notes of interest
, alla stregua della funzione explode ( ) del PHP per intenderci. The string returned in locationString is "split" by the method componentsSeparatedByString , like the function explode ( ) in PHP for instance. I put the example I proposed - but commented - the code to retrieve even the Google accuracy parameter, precision or scale factor, denoted by zoom .
Source as
For completeness, I made a small example application with which you can try the method proposed above, enter any address and the iPhone will show on the map.


Download Source
I thank the team devAPP for the inspiration of this article.
Continued ...
To find the coordinates of an address or latitude and longitude, we can use this simple and useful hacks. Open the site Google Maps . Once on the map looking for the address you want (for example via Cortese 10, Modena).
Continued ...
Also this time I reply to a comment with a post, given the general interest. Armando asked me if it was possible, using Google Maps, Latitude and Longitude obtained from a city name or street. The answer is yes! Using the Google Maps API geocoding service you can ask Google directly from reprocessing our textual information (state, city, etc.) in geographic coordinates. You can try an online example of documementazione Google directly on the site.
Continued ...
She was released the beta 0.6 component UMAP for Flash CS3 (Actionscript 3.0) - is also present in the package version for Flex. Among the news we see the adoption of OpenStreetMap as the default provider. Also added was an advanced manager Marker and a series of various optimizations.
Continued ...
Mapstraction is a JavaScript library that acts as an intermediate layer to use the maps of the most popular systems available today. The idea is to provide a wrapper, an interface that can unify the code whatever, then the type of rendering engine maps that you want to use.
Are available on site demos and documentation . The library is downloadable for free. Supported in this release are the most famous engines 9: OpenStreetMap, Yahoo , Google , Microsoft , Map24, MultiMap, MapQuest, FreeEarth and OpenLayers.
Supports the creation of Point, Line and Polygon. You can insert your Image gallery overlay. Interesting support for geocoding of street addresses and directions of the brand! Net compatibility with feeds GeoRSS and KML .
From the examples of the code once you understand how useful a tool of this type. Each "Interface" ( Google , Microsoft , Yahoo , etc ...) it has its own set of APIs. Through Mapstraction , however, we can write a single block of code and let the end user the choice of provider to use. For example, when you initialize the library, the following line of code:
1 2
| / / Initialise the map with your choice of API new Mapstraction ( 'mapstraction' , 'google' ) ; var = new mapstraction Mapstraction ('mapstraction', 'google'); |
Determines the engine Google ! It is without saying that, I replaced the string 'google', immediately change the rendering engine of the maps!
1 2
| / / Initialise the map with your choice of API new Mapstraction ( 'mapstraction' , 'microsoft' ) ; var = new mapstraction Mapstraction ('mapstraction', 'microsoft'); |
Although the library is not really complete, can be integrated into a single framework all the features "spread" of the individual libraries. The rendering engine Microsoft, for example, allows display "as the crow flies." OpenStreetMap and Google maps have excellent management of the road, including the Italian ones. In short, for those who must face the development of an application with the use of maps and can not - just - to decide which technology to use for development, Mapstraction allows - in fact - to cut oneself, to resolve the dilemma by introducing, in fact, third actor, and in this way, give us the ability to change the rendering engine at any time. So good idea to follow and to use!
Continued ...
Latest Comments
Simon : I tried last night putting everything into functions.php, okay, jquery forms, and tabs jQueryUI them ...
Giovambattista Fazioli : @ Simon: I recommend cleaning to enter a code like that in ...
Simon : @ Giovambattista Fazioli: Thank you for your patience, it's all clear ... now I feel now, ...
Giovambattista Fazioli : @ Simon is quite simple. Now I do not know if you need hand frontend, backend o. ..
Simon : Hello, sorry if you steal this space ... I'd need help if possible ... I need to ...