Set location on google map - google-maps

I have created one small application, where user can store his/her contacts with full address including map. Therefore I am using the Google Maps API, where user can point out his/her address.
For this I have given address fields with Country, State and City. When user entered this information, I am showing the default address on Google Maps, then the user has to drag the marker/pointer onto his/her exact location.
Now, in this case I want the zoom level of googles map to be set as per location's population.
This means if the user entered city with no mans land (less population or any desert place or any jungle place or very small area on city then zoom level should be more, so user can see proper area on map) otherwise zoom level should be less.
Can some one guide me how to do this?

This won't be possible using the Google API's alone, (I'm unsure if demographics info has been released for the US, I know it was in the works, but it certainly won't work elsewhere). You will have to find an external source to provide your demographics information for you.
The Google API's do not keep a public record of population density.
You could however be a but more tricksy and use an approximation. You could for example do a places search in the area (using an arbitrary radius), count the number of results and use this to set your zoom level (again using an arbitrary value to determine high/medium/low etc). It's a fair assumption (though still an assumption) that any area with a large number of 'places' returned will be densely populated.

You don't need to base this on the population of the location. Please check the follwing link. I think it should give you an idea of the options you have.
Google Maps API v3 - Geocoder results issue with bounds
Check both my question and my answer. You will probably want to use the viewport object.

Related

google places and geocode not returning full results list

I am doing some mapping work and need to find latitude and longitude of villages in india many of which are small and rural. I am having trouble finding the full set of locations with the same name, for example a village named 'Kallanai' (see api links below, note they need appropriate keys for the places API to run on your computer). I can find the one I'm looking for in google maps by entering www.google.co.in/maps/place/Kallanai into the browser however it will not turn up in the geocoder or places api without specifying the associated pin code (analogous to zip-code). Can anyone explain why the basic searches for either the geocode or places API using the village name alone do not return the village with the pincode 625501 in the results?
e.g.
Google places:
https://maps.googleapis.com/maps/api/place/textsearch/json?query=kallanai&sensor=false&key=enter your key
https://maps.googleapis.com/maps/api/place/textsearch/json?query=kallanai+625501&sensor=false&key=enter your key
will post google geocode links in follow up as stackoverflow will not let me include more than 2 links in my post without more points.
In a world where autocomplete is common and almost taken for granted, Google Maps has (long) switched to showing just the one results your most likely looking for.
Places Autocomplete API might get you more of what you're looking for, but it would still be a sub-optimal fit for database-like queries like this. It works best when you have users typing, each of them knowing which Kallanai they want, so they can select the suggestion that matches, and they can add details (e.g. PIN code) to get it if the suggestion doesn't show up at first (max 5 suggestion show each time).
Google does Geocoding in a different way from classic GIS databases. To obtain all cities [with a given name] in a given country, you'd probably need a database like GeoNames or Natural Earth.

How can I create links Google Maps that either use the place name in the query (for known places) or just the address otherwise?

I am creating links to Google Maps for a large number of locations using this URL pattern:
https://www.google.com/maps?q=[query]
In many cases, Google knows that the particular business exists at that location. In those cases, I want to include the place/business name in the query so the resulting map shows additional information about the business (e.g. name, phone numbers, site URL, office hours, etc.). For example:
https://maps.google.com/?q=Child+Guidance+Center,+Inc.+525+Cabrillo+Park+Dr+#300+Santa+Ana,+CA+92701
But, if the place isn't known, including the business name in the query prevents the map from adding a marker to the correct address. For example:
https://maps.google.com/?q=Awesome+Paint+527+Cabrillo+Park+Dr+Santa+Ana,+CA+92701
It can cause the map to be totally zoomed out, or focus on a competing business with a somewhat similar name in the same general area.
How can I make this work better? I would like the map pin to always go in the correct location for the address I specify. If the business name I provide is known to Google at that address, then I'd like the nice panel of extra information. If it is not known, I just want the pin.
Thank you.
This similar question is asking about creating embedded maps, which is a slightly different case Google map to show name of location if found, otherwise just the address. I'd prefer to avoid extensive use of the APIs because I'm worried about exceeding the free limit, but more generally geocoding the address that worked above (Child+Guidance+Center,+Inc.+525+Cabrillo+Park+Dr+#300+Santa+Ana,+CA+92701) returns zero results like so:
http://maps.googleapis.com/maps/api/geocode/json?address=Child+Guidance+Center,+Inc.+525+Cabrillo+Park+Dr+#300+Santa+Ana,+CA+92701

Get street suggestion (start point) in GMaps Directions service

I'm using Google Maps API 3 for returning directions from user's input address (destination node) to a Store (predefined start node).
I ask for user's address (not geolocation but through a simple input field) but I wouldn't like the user to narrow their input by entering extra info like postcode, state, city. I just want to make the input of the user as little as possible, e.g. 123 Road street.
However, when I type an address with a common name (like 25 Main street), the route I get is possibly the first result that Google has available, even if it is 3000 miles away when the user's address could be 2 miles away.
I have read all Google's documentation in regards to Directions service but I couldn't find anything that relates to street suggestions. Do you know how I can serve suggestions to the user so that the start address would be the exact match of user's preference?
I'm afraid this is impossible to achieve without any detail for the real location of the user.
Of course you would be able to filter results(regardless of the used service) by the distance, but how could you know if the user is located at the nearest address...you can't.
A possible solution may be to use a places-autocomplete (i guess that's what you mean by "serve suggestions"), the user would be able to choose his location from the predictions.
Another approach:
Instead of a input-field you may let the user click on the map to mark his location

Reverse geocode using MKReverseGeocoder

Google Terms says I can only use reverse geocoding in conjunction with a google map.
Is it ok if you first see the address in a uitableviewcell and then on a click see the location in a map (is this "in conjunction") ?
Tried two other free services but they don't find all locations as it seems.
Edit
I see in an answer that I need to clarify
The app should get the current gps location first using CLLocationManager and this location (latt,long) should be translated into a street/city name and displayed on the cell.
Then, after getting a green/yellow light and a location description that fits the accuracy needs of the user, the user should normally click on the cell causing a map to load with stores of a certain company that are nearby. ("normally" because he could also hit another cell "Enter different location").
Caveat emptor I am not a lawyer and this advice is not a substitute for actual legal advice.
Assuming that when you click on the address, only then the address is reverse-geocoded, and the marker is displayed on the map, then yes, that would certainly count as "in conjunction" in my book.

Generate google map based on UK postcode

Is it possible to do a google map lookup using the google maps API from a UK postcode? I know you can search by UK postcode on their website, but this converts to lat / long. I don't have access to the PAF database to be able to convert to long / lat.
An example:
Users have an item to sell. One of the details of that item is a postcode, where the user / item is located. When the items are displayed on the front end of the website, there needs to be a google map of the items location generated using the postcode.
If this is possible, how do I do it?
What about using:
<img src="http://maps.google.com/maps/api/staticmap?center=POSTCODEHERE&zoom=14&size=200x200&maptype=roadmap&markers=color:ORANGE|label:A|POSTCODEHERE&sensor=false" style="float: right">
Then replace POSTCODEHERE in the two sections above with their postcode.
You can change the size from 200x200 or the marker colour, label etc. too if you wish.
You can do it purely though Google maps.
I did it for a client earlier this year and have just had to do a few modifications. I also did some direction-grabbing. It's all pretty simple but best viewed in context.
Take a look at the source of the page I made.
Google does not provide a geocoding api in the UK because of the licensing model the Royal Mail releases postcode data under.
The are however some tools that people have written that enable geocoding using google, but that would be technically illegal afaik.
One option then is to use one of the several uk geocoding providers. I don't want to sound lazy but they are easily googled. They typically charge a few pence per geocode.
It's (now) very easy to do this using google's LocalSearch API:
function usePointFromPostcode(postcode, callbackFunction) {
localSearch.setSearchCompleteCallback(null, function() {
if (localSearch.results[0]) {
var resultLat = localSearch.results[0].lat;
var resultLng = localSearch.results[0].lng;
var point = new GLatLng(resultLat,resultLng);
callbackFunction(point);
} else {
alert("Postcode not found!");
}
});
localSearch.execute(postcode + ", UK");
}
callbackFunction() will receive a GLatLng object with, in my experience, very accurate coordinates. In fact, it's trivial to then feed that GLatLng to a GClientGeoCoder's getLocations() method and get back full Placemark details, which include details down to the level of address range (e.g. 1-18 Foo Street).
The real question is: how legal is that?
you need the PAF database, each postcode is held as a polygon, so unless you have that initial data you cannot restrict the search to the polygon, or to a radius around the centrepoint.
The postoffice will sell you all the data you require though, prices start from £85pa.
PS. Google does it because they have the PAF database, when you type in the postcode, they lookup the centre and display that on their map.
The folks behind openstreetmap.org have been working on a free equivalent - I don't know how ready for prime time it is, but FWIW:
http://freethepostcode.org/
http://www.websemantics.co.uk/resources/postcode_to_coordinates_conversion_tool/
Site will provide you with a longitude and latitude which you can place right into your google code.
Small UK business or charity can apply for a free licence of use PAF.
https://www.poweredbypaf.com/register-for-free-use-of-paf/
No one seems to have searched very hard... there is a freely available list of UK postcodes and positions out there. More importantly its all redundant because Google maps provides the ability to search by post code to begin with. Even using the API is a redundant extra given that the service is provided over the internet... there is nothing to stop you sending a http request yourself and displaying portions of the returned data, as long as you preserve any necessary copyright messages etc..