How to get a static map searching by city with an specific country - google-maps-static-api

I'm trying to get a map img from Google Static Maps API,
If I do the following requests:
https://maps.googleapis.com/maps/api/staticmap?size=1536x836&center=+Spain,+Andorra&zoom=8&markers=color:red%7Clabel:D%7C,+Andorra+Spain&key=badKey
center and label variations: +Andorra,+Spain , +Andorra,+ES, +Spain+Andorra, +Andorra+Spain
I get always Andorra La Vieja, country Andorra,
I expect to get Andorra, Spain,
The only way I could obtain Andorra Spain is specifying the state / province (Teruel).

Upon checking, this behavior is working as intended which can also be replicated in Geocoding API using the Geocoder tool which returns the country "Andorra" when geocoding the address "Andorra, Spain".
Since the address string "Andorra, Spain" is slightly ambiguous, and there are two addresses that contains "Andorra", the API was only able to return the country Andorra. To have better results, you need to be more specific with your query by also providing the admin levels "Teruel" or "Aragon" or a postal code, as you have also mentioned in your post. See full address result here.

Related

Bing Maps throwing "Invalid Geocode" error on street intersection that it is able to get the Latitudes and Longitude from

I am currently working on a project that involves calculating Duration matrices from a collection of thousands of addresses using NEO4J and Bing Maps API. Since the data is sensitive, we're going to use the mock address (which actually produces the same issue I'm describing) '72ND & DODGE, OMAHA, NE 68132' to represent the format intersection addresses are being sent to Bing Maps API using their keys and basic url requests.
To preface this: the issue isn't with my code (which is also sensitive data), as all my code is doing is sending one url string of the above format plus the authorization key to Bing Maps and awaiting a response that contains the duration data of the trip. My issue is Bing Maps being seemingly unable to handle or work with intersections of streets to calculate distances/durations from other locations. When I throw these addresses into Bing/Google Maps in the web browser, they are able to be found and calculated in the exact same format as the above example.
I start off my program checking if an address exists/is valid by having it find the latitude and longitude of each address, so for the example '72ND & DODGE, OMAHA, NE 68132' it found: Lat: '41.259690' and Long: '-96.023770'. If it is unable to find the Lat/Long of an addresses, then it throws the 'Invalid Geocode' error, but in this initialization context it means the address does not exist, or is poorly formatted, which makes sense and is why I did this for the initialization phase.
However, if I go to use '72ND & DODGE, OMAHA, NE 68132' for any duration calculations between other addresses, it throws the 'Invalid Geocode' for '72ND & DODGE, OMAHA, NE 68132' over and over again with no explanation on why even though it passed the Lat/Long check. I'd also like to mention that this issue isn't consistent, as some intersections do not work while others do, but there is no consistency in knowing which ones will or will not work. Thus, I am ultimately wondering if Bing Maps is unable to calculate certain addresses no matter their formatting or whatnot.
Be sure to encode your query before putting it into the URL. Especially when you have & in your query since it would then break your query up, thinking you were asking just for 72ND and the rest of your query is query string parameter name. This is documented in the best practices section here.
In Java you can encode the query parameter like this:
String baseURL = "https://dev.virtualearth.net/REST/v1/Locations?key={BingMapsKey}&query=";
// query string
String query = "72ND & DODGE, OMAHA, NE 68132";
// URL encode query string
String encodeStr = URLEncoder.encode(query, StandardCharsets.UTF_8.name());
// final url
String url = baseURL + encodeStr;
Here is an example of how your query URL should look:
https://dev.virtualearth.net/REST/v1/Locations?key={BingMapsKey}&query= 72ND%20%26%20DODGE%2C%20OMAHA%2C%20NE%2068132

How to add housenumber in nominatim API in OSM

The Nominatim API states
'street= '
It implies that there is a space between <housenumber> and <streetname>.
However, when I try to enter a space in the URL
https://nominatim.openstreetmap.org/search?city=berlin&street=skalitzerstrasse 9&format=json
I get an error (understandable).
How to properly add the housenumber?
First of all it's better to prefix the housenumber and than you just urlencode the space like:
https://nominatim.openstreetmap.org/search?city=berlin&street=142%20skalitzer%20straße&format=json
You'll also have only the street as a response if a housenumber (like 9) is not present or mapped, that's why I have chosen a different housenumber as an example.

CLGeocodeCompletionHandler only has one placemark entry

The documentation for
- (void)geocodeAddressString:(NSString *)addressString completionHandler:(CLGeocodeCompletionHandler)completionHandler;
The documentation clearly states:
In the case of forward-geocoding requests, multiple placemark objects
may be returned if the provided information yielded multiple possible
locations.
states that it returns an array of placemarks. However, even if I search for objects I know for certain have multiple entries (Hollywood, washington, Denmark, main street, ect.) i always only get one entry.
Some people just shrug and say use the google API instead, but i fear for the request limit.
Is there some setting or hack to fix this, or is the CLGeocoder simply broken ?
I would definitely suggest using Google Geocoding API - it is simply superior. I also argue, that you should not fear the usage limit for Google Geocoding APIs requests.
If you are developing mobile application, I suggest implementing client-side geocoding - that means, that every device queries directly Google API. As it is directly stated in Google's own documentation
geocoding limits are per user session, there is no risk that your application will reach a global limit as your userbase grows.
More info in geocoding strategies docs and geocoding docs.
MKLocalSearch is the answer here:
let request = MKLocalSearch.Request()
request.naturalLanguageQuery = "addressToBeSearched"
request.region = MKCoordinateRegion(center: span: )
let localSearch = MKLocalSearch(request: request)
localSearch.start { response, error in
// returns (MKLocalSearch.Response?, Error?) -> Void
// which ultimately has an array of MKMapItem from which you can extract a placemark.
}
This returns the nearby and not only, points of interest, places, etc.
The only drawback I can think of is that you have to provide the current location in the initializer for MKCoordinateRegion and the span.

How to get multiple adrresses from GoogleGeocoding API?

I want to retrieve all the address locations (latitude,longitude,format address) for a single 'search address' request (a little vague such as "Tata Consultancy Services") in MapKit.
I searched on the net and came across GoogleMapsAPI WebServices .
http://code.google.com/apis/maps/documentation/geocoding/
But problem with response is that, it returns only a 'single object' in 'results array' response for a address search.
As an example if you search "Tata Consultancy Services" you get only one location whose formatted address is "TCS Rajshree Business Park, Tadiwala Rd, Sangamvadi, Pune, Maharashtra, India".My question is how can i get details of other locations as we all know that this is not the only office of TCS.
I would like to quote two documentation links related to your problem.
http://code.google.com/apis/maps/documentation/geocoding/#GeocodingRequests
"Generally, only one entry in the "results" array is returned for address lookups, though the geocoder may return several results when address queries are ambiguous".
So you may found one or more result. but as you are requesting it from iPhone and sensor is by default true. you receive nearest matching result for your query.
The solution is "Viewport Biasing".Please find its details at below link under heading name "Viewport Biasing":-
http://code.google.com/apis/maps/documentation/geocoding/#Viewports
Another options you can try on:
try setting sensor as false.
try region biasing as described on the same page cited above.
try some other word like "hotel near placename" and check the
response result

How to get exact phrase match out of Graph API search

Looking for a way to get an exact phrase match out of the Graph API's search endpoint. For example, all activities with "dogs and cats" in them. Putting the phrase in quotes doesn't seem to work, the API will return activities containing those words, but in any order.
curl -v "https://graph.facebook.com/search?q=%22dogs%20and%20cats%22&type=post&limit=75&access_token=&since=Wed+Jan+25+20%3A59%3A30&until=Wed+Jan+25+20%3A59%3A40"
returns and activity whose text is:
"Ohhh man it's raining dogs cats lobsters crab birds and horses up here. I'm scared!"
"dogs" "cats" and "and" are all in that post, but not in order.
Yeah I faced the same problem. There's a similar question that might help Using the Facebook Graph API to search for an exact string
Facebook doesnt allow exact phrasal matching drectly, atleast not at the API level, You would have to fetch the entire data and programmically check for exact matches (too slow though).