Google Maps Boundaries (limiting location data to a Lat/Long Boundary) - iphone

Anyone know how to get thew Google Maps API HTTP request/response to only return me Locations that fall within Australia ?
I thought I could just add:
bounds=lat, long | lat Long
Creating a square boundary based off Coordinates, but Google for some strange reason isn't liking it.
[NSString stringWithFormat:#"%#%#+Australia&bounds=-9.102097,104.765625|-44.902578,159.697266&sensor=false&region=au", kGoogleGeocodeURL, params];

Problem resolved, it turns out that the search string was correct, but I needed to use UTF8Encoding, as NSString didn't like the Commas.

Related

Bing Maps search defaults to Lancaster

I don't know if anyone have noticed this, when requesting from Bing maps REST service for some locations, or if the query was not well formed, the response from Bing maps gives the coordinates of Lancaster, Lancashire, as if it was defaulting to this location...
try this request and check the coordinates, it should yield the coordinates of "Bethnal Green, London - East", instead it is "Lancaster, Lancashire":
http://dev.virtualearth.net/REST/v1/Locations?locality=Bethnal+Green+&adminDistrict=%22London+-+East%22&countryRegion=UK&o=xml&key=BING_MAPS_KEY
Any info about this and how to stop it is appreciated.
What is happening is that the geocoder isn't understanding your lower level address information so it moves up through the address until it finds something. In this case it is returning a coordinate for the center of the UK. This just happens to be near Lancaster, Lancashire. If you look at the Name or address property of the result you will be able to see this pretty clearly. Also, since you are working with the REST services take a look at these tips and tricks: http://www.bing.com/blogs/site_blogs/b/maps/archive/2013/02/14/bing-maps-rest-service-tips-amp-tricks.aspx

Displaying google direction api response on Map

I am using google api V3 in my iOS App,
I requested to google api direction service, by http GET method, I got a very large json response, I got many alternate routes from origin to destination, now I want to show the route of each alternative on map, how should I done this ? is there any need to integrate google sdk in iOS, or can i use webView only, please help me, and suggest the simplest way.
Thanks in advance
you do not need to include any google SDK to draw the route over map. Look at the following classes.
MKPolyline
MKPolyLineview
The google map api Direction service will give you the legs(coordinates) to draw the route between two specific points.
As you already have the json response from the Direction api now you have to parse the json and get all the legs point from the json to create Coordinate array.
Jsonkit for parsing
These points may be or mostly encripted. How to decode the Google Directions API polylines field into lat long points in objective-C for iPhone?
If you have the coordinates array then first you have to create a CLLocationCoordinate2D array like following:
CLLocationCoordinate2D *pointArr = malloc(sizeof(CLLocationCoordinate2D) * [your_CoordinateArray count]);
for(int i = 0; i < [your_CoordinateArray count]; i++){
pointArr[i] = [your_CoordinateArray objectAtIndex:i];
}
Then you have to add the polyline to your map
MKPolyline *line = [MKPolyline polylineWithCoordinates:pointArr count:[your_CoordinateArray count]];
if (nil != line)
{
[your_Map addOverlay:line];
}
Then you have to implement the following map delegate:
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
MKOverlayView* overlayView = nil;
lineView = [[MKPolylineView alloc] initWithPolyline:overlay];// lineView is an ivar, object of MKPolylineView
lineView.fillColor = [UIColor greenColor];
lineView.strokeColor = [UIColor greenColor];
lineView.lineWidth = 10.0;
lineView.alpha = 0.9;
overlayView = lineView;
return overlayView;
}
Now, if you want to show two different routes between two points then you have to create two different array of coordinates and apply the above method for both Arrays
Hope this will help you.
There is no need per say to integrate google sdk and you can simply use webView since I believe the webView gives you alternative views, but the user interface is much cleaner in the SDK than online. But at this moment, I don't believe the SDK allows other apps to show the alternative routes from what I've used of the new SDK. The code in maps.google.com is now considerably different from that in
the API and has access to different services. In particular, it has a large external module, mod_suggest.js, that doesn't exist in the API. But you may be able to implement it by
1) Throw the request at maps.google.com, and let it do the suggestions,
i.e. open a new browser window and pass it something like
http://www.google.com/maps?f=d&source=s_d&saddr=Jurong+West,+Singapore&da
ddr=Ang+Mo+Kio,+Singapore&hl=en
2) Just display the normal route and the avoid highways route.
3) Try to guess sensible waypoints to add in the middle of he route that
might lead to reasonable alternatives. That's not easy unless you have a
database of highways or highway intersections, and can look for such an
intersection that's somewhere between your start and end points (for
some approximate value of "between").
There may be problems using lat/lng coordinates for the waypoints,
particularly if there's a dual carriageway involved. If the coordinates
are for a point on the wrong carriageway, GDirections will drive a
considerable distance out of your way so that you visit the wrong side
of the road. But even using street names you may well get strange kinks
near the waypoints, like this:
from: Jurong West, Singapore to: Ayer Rajah Expy singapore to: Ang Mo
Kio, Singapore
Perhaps the only way to really deal with that is to include points on
both sides of a dual carriageway, and well clear of roads that cross
underneath or overhead, and then try to filter out the ones that are
silly.
Consider these examples
from: Jurong West, Singapore to: 1.32558,103.740764 to: Ang Mo Kio,
Singapore
from: Jurong West, Singapore to: 1.32582,103.740764 to: Ang Mo Kio,
Singapore
One of those adds 7 minutes to the trip by a complicated excursion to
visit the wrong side of the road.
Writing code to filter out silly routes isn't easy. As a first
approximation, you could discard routes that have estimated times that
are more than, say, 10% longer than the initial route. And you can also
compare the durations for pairs of points on opposite sides of a dual
carriageway and always discard the slower one.
Writing code to discard duplicate routes isn't easy either. For example,
a point on Bukit Timah Expy or Kranji Expy might create a route that's a
duplicate of Google's Seletar Expy suggestion.
You might want to look at: http://www.geocodezip.com/example_geo2.asp?waypts=yes&addr1=Jurong+West,+Singapore&addr2=Ang+Mo+Kio,+Singapore&waypt=Ayer+Rajah+Expy+singapore&geocode=1&geocode=2
But that may not be a legal implementation since the API does not allow it. Hope this helps.

CLGeocoder Only Returning One Placemark

I have a problem with CLGeocoder where when I call geocodeAddressString:withCompletionHandler I only ever get one result back, despite knowing that the inputted string should return more than one value. The class reference even states:
In the case of forward-geocoding requests, multiple placemark objects may be returned if the provided information yielded multiple possible locations.
However, my placemarks array only ever has one item in it:
[geocoderDestination geocodeAddressString:destination completionHandler:^(NSArray *placemarks, NSError *error){
NSLog(#"array count:%i", [placemarks count];}
Thank you for any help.
I have used strings such as "Piccadilly, UK", "Union Street, UK" which have only returned one result. Now that I think about it, putting UK on the end might be the contributing factor.
I dont know about CLGeocoder but if your requirement is a location search another way is to use google location search url http://maps.google.com/maps/geo?q=london which returns a json containing the matched location information.
Instead of UK use United Kingdom it will give you some related result.
Try to add some more info in your address.
One more thing UK is not a valid country code it's GB but it seems that putting GB instead of UK didn't solve the problem.
Moreover CLGeocoder is not as smart as Google Maps API right now because apple uses its own server to decode addresses so you can use Google services.

Getting GPS locations and other attributes - BEGINNER

I am currently doing this tutorial to get the GPS coordinates of my present location. I need to know what these values means?
The first 2 values are the geo-coordinates, and i don't know what the other attributes are ?
From Apple's iOS Developer Library what you are seeing as a result of the description selector being sent to your CLLocation object (which represents your current location and other location-related info):
A string of the form <<latitude>, <longitude>> +/- <accuracy>m (speed
<speed> kph / heading <heading>) # <date-time>, where <latitude>,
<longitude>, <accuracy>, <speed>, and <heading> are formatted floating
point numbers and <date-time> is a formatted date string that includes
date, time, and time zone information.
What you probably want to do now is extract info from your CLLocation object by accessing its various properties (e.g. CLLocation.altitude will return the altitude only). Generally, aside from debugging purposes to the console, you would not want to print or display to the user the result of [CLLocation description] which is what you have there!

How to effectively draw Polyline using Google API?

i'm drawing polyline on MapView using "google direction API" and getting success in it.But the thing is that it draws straight line between two locations(with their longitude and latitude).I don't know how to draw line effectively like shown by google maps,when we click "get directions" between two locations.
I suggest taking a look at an SDK like CloudMade, this makes it very easy to implement custom maps and route's, you'll be able to draw a route between two locations within about 10 minutes of installing the SDK. Here is a quick example to get you started if you go down this route, excuse the pun.
CLLocationCoordinate2D initLocation;
initLocation.longitude = -0.127523;
initLocation.latitude = 51.51383;
CLLocationCoordinate2D destination;
destination.longitude = -0.125;
destination.latitude = 51;
TokenManager* tokenManager = [[TokenManager alloc] initWithApikey:#"YOUR API KEY"];
CMRoutingManager *routeManager = [[CMRoutingManager alloc] initWithMapView:mapView tokenManager:tokenManager];
[routeManager findRouteFrom:initLocation to:destination onVehicle:CMVehicleWalking];
You can find more information here in the documentation. Another alternative would be to use route-me which would allow you to choose from the following map sources:
OpenStreetMap, Microsoft VirtualEarth, CloudMade, OpenAerialMap, OpenCycleMap, SpatialCloud, and two offline, database-backed formats (DBMap and MBTiles)
Although personally i do not have any experience with route-me, so can't point you in the right direction to get started.
If you are adement on sticking with MKMapView, this blog post will get your started in the right direction.