I can use Core Location to get a GPS coordinate and MapKit to convert GPS coordinates to address...?
What I'm looking for is to take a standard US (if that makes any difference )address (BTW, is there a specific format required?), and display it with a pin in a MapView. Is there any sample code to demonstrate this?
I don't want to get just the current location, but be able to put in any location.
I can use Core Location to get a GPS coordinate and MapKit to convert GPS coordinates to address...?
What I'm looking for is to take a standard US (if that makes any difference )address (BTW, is there a specific format required?), and display it with a pin in a MapView. Is there any sample code to demonstrate this?
I don't want to get just the current location, but be able to put in any location.
Your going to want to make a nsurlrequest with the google maps api to geocode address.
I can use Core Location to get a GPS coordinate and MapKit to convert GPS coordinates to address...?
What I'm looking for is to take a standard US (if that makes any difference )address (BTW, is there a specific format required?), and display it with a pin in a MapView. Is there any sample code to demonstrate this?
I don't want to get just the current location, but be able to put in any location.
As the other poster said, you need to use the google maps web API to do this. The map kit (or an other part of iOS) doesn't support address lookup. The good news is that doing this kind of request is REALLY easy.
The following 2 lines will return a lat/long for an address in theAddress:
Where lat and long are decimal latitude and longitude values. The 200 is a success code, and the 8 is a zoom factor. Treat numbers other than 200 at the beginning as an error, ignore the second number, and take the last 2 as your lat/long. You can use the NSString method componentsSeparatedByString to separate the returned locationString into it's components.
A couple of caveats:
-This uses a form of the Google API that Google deprecated this spring. It may be shut down as soon as a little less than 3 years (Google's docs say that their deprecated APIs will continue to be supported for 3 years from the date of deprecation). That part of the google maps API has been replaced with a new version (which is harder to parse).
-All the google maps APIs are subject to Google's terms of service. You are only supposed to use the results to display addresses on a Google-branded map. The way I read the TOS, using the API to create annotations on a map-kit map meets those terms because the map has the Google logo on it. However, I am not a lawyer, and advise you to read the TOS yourself (or better yet, hire a lawyer to read them and advise you.)
-The code above submits a synchronous request. If Google's host hangs, your code will lock up until the request times out. It would be better to use an NSURLRequest and NSURLConnection to submit an async request, but that's more work. You need to create a couple of objects for each request, teach your code to handle 3 or 4 delegate methods, collect the incoming data, handle success and error completion messages, etc. You also have to write code that either only allows 1 async request at a time, or handles multiple pending requests. That said, I took the easy way out, and used the sync request shown above. In my testing, it works quite well, and only takes a few seconds.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Never mind Duncan, I didn't see your post yet. Thanks for that.
This app is just for a friend, and I don't plan on selling it. Regardless, could you provide some basic info on their new format, just for future-proofing purposes? Thanks!
Never mind Duncan, I didn't see your post yet. Thanks for that.
This app is just for a friend, and I don't plan on selling it. Regardless, could you provide some basic info on their new format, just for future-proofing purposes? Thanks!
I don't have the docs in front of me. If I can track them down I'll post a link. It's a question of wading through a lot of info on Google's site.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
I would think that I would have to convert spaces in the address to %20 character sequences...How would I do that? I'm thinking of using componentsSeparatedByString: on the address, but I'm not sure that method supports plain spaces...But if it did, then I would join those with a stringWithFormat: method, as well as %20s. Would that be right?
I would think that I would have to convert spaces in the address to %20 character sequences...How would I do that? I'm thinking of using componentsSeparatedByString: on the address, but I'm not sure that method supports plain spaces...But if it did, then I would join those with a stringWithFormat: method, as well as %20s. Would that be right?
Just take the address you get from the user and do this:
Actually, I just realized that characters like "&" will likely mess up the google geocoding API. I have a routine that parses strings and escapes a set of characters that I specify. It looks something like this (I reworked it slightly to make sense outside of my code library):
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
how ever i want to show my current location as well on that map only
i can track my current lat and long using GPS but i dont know how to display them to map if i pass simply like above then i am getting just address from current lat and long
When I did it for the first couple of times, i got the result string correctly.
But after a while it started giving me this error stating : "Registration timer expired, but client is still registering!" and the location string value returned is (null).
When this happens it hangs the app for about 3-5 mins.
Has anybody encountered this before and Any ideas on how to solve this? Pls help.
Thanks In Advance
Quote:
Originally Posted by Duncan C
As the other poster said, you need to use the google maps web API to do this. The map kit (or an other part of iOS) doesn't support address lookup. The good news is that doing this kind of request is REALLY easy.
The following 2 lines will return a lat/long for an address in theAddress:
Where lat and long are decimal latitude and longitude values. The 200 is a success code, and the 8 is a zoom factor. Treat numbers other than 200 at the beginning as an error, ignore the second number, and take the last 2 as your lat/long. You can use the NSString method componentsSeparatedByString to separate the returned locationString into it's components.
A couple of caveats:
-This uses a form of the Google API that Google deprecated this spring. It may be shut down as soon as a little less than 3 years (Google's docs say that their deprecated APIs will continue to be supported for 3 years from the date of deprecation). That part of the google maps API has been replaced with a new version (which is harder to parse).
-All the google maps APIs are subject to Google's terms of service. You are only supposed to use the results to display addresses on a Google-branded map. The way I read the TOS, using the API to create annotations on a map-kit map meets those terms because the map has the Google logo on it. However, I am not a lawyer, and advise you to read the TOS yourself (or better yet, hire a lawyer to read them and advise you.)
-The code above submits a synchronous request. If Google's host hangs, your code will lock up until the request times out. It would be better to use an NSURLRequest and NSURLConnection to submit an async request, but that's more work. You need to create a couple of objects for each request, teach your code to handle 3 or 4 delegate methods, collect the incoming data, handle success and error completion messages, etc. You also have to write code that either only allows 1 async request at a time, or handles multiple pending requests. That said, I took the easy way out, and used the sync request shown above. In my testing, it works quite well, and only takes a few seconds.
Newbee, do you still need assistance with this? I am actually using the newer Google API to accomplish this. I've received the XML string from the Google API, and I'm about to write the XML Parser using the standard Apple xml parsing routines.
And here is a basic example of the code needed to retrieve the XML containing the Lat & Long. The string locationXML contains the complete string that is ready for parsing.
Note that string strGeoCode has a parameter of "sensor=true" at the end of the string. That parameter is required. It says that the device has a location sensor (GPS or Network). False obviously means that it doesn't. The value also has to be lowercase.