Determining the Place according to latitude and longitude - google-maps

I'm using google maps API to determine a building(Place) which is a Google Point of interest. I'm trying to get the place reference for future use. but due to API limitation or whatever limitation. I can't get the exact place. As an example below latitude longitude belongs to "The university of Sydney". Using this code I could derive University of Sydney but as second result and also I tried many lat long but sometime appropriate result comes in the end or first. These places are prominent to Google Places Search system. The radius of this request looks lame to me. Is there any way to retrieve the exact place ?
var pyrmont = new google.maps.LatLng(-33.88858402464521, 151.18735671043396);
map = new google.maps.Map(document.getElementById('map-canvas'), {
center: pyrmont,
zoom: 15
});
var request = {
location: pyrmont,
radius: 1,
};
infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);
}
Advanced Thanks

Related

Can i get the exact results as like google by passing just keyword?

I want to search places by keyword match.
I have used Google Map Places API for this and passed the following arguments for search in this name is dynamically added from search textbox.
var search = {
bounds: map.getBounds(),
keyword:[name] //name=dentist
};
I am getting results in this but these results are not same as I got from google search.
Suppose if I enter dentist and choose location Ahmadabad in auto complete then I need the search results exactly as I search "dentist in ahmedabad" in google.
Is it possible to get same results as google?
Help will be appreciated.
Check Places Library:
The functions in the Google Places JavaScript library enable your application to search for places (defined in this API as establishments, geographic locations, or prominent points of interest) contained within a defined area, such as the bounds of a map, or around a fixed point.
In your case use Text Search Requests:
The Google Places Text Search service is a web service that returns information about a set of places based on a string — for example "pizza in New York" or "shoe stores near Ottawa". The service responds with a list of places matching the text string and any location bias that has been set. The search response will include a list of places. You can send a Place Details request for more information about any of the places in the response.
Text Searches are initiated with a call to the PlacesService's textSearch() method.
service = new google.maps.places.PlacesService(map);
service.textSearch(request, callback);
You must also pass a callback method to textSearch(), to handle the results object and a google.maps.places.PlacesServiceStatus response.
var map;
var service;
var infowindow;
function initialize() {
var pyrmont = new google.maps.LatLng(-33.8665433,151.1956316);
map = new google.maps.Map(document.getElementById('map'), {
center: pyrmont,
zoom: 15
});
var request = {
location: pyrmont,
radius: '500',
query: 'restaurant'
};
service = new google.maps.places.PlacesService(map);
service.textSearch(request, callback);
}
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
var place = results[i];
createMarker(results[i]);
}
}
}
Hope it helps!

Pinpoint location (latitude & longitude) in Google Maps

I have data of a location's latitude and longitude. I want to display it into a map in my application. I planned to use Google Maps to display this location to user.
To do this, would I need the Google Maps API? or the Google Maps Coordinate?
I've looked into their website, but all those varieties just makes me confused.
I only need it to display the data (latitude and longitude) into visual (map) to make my application more user-friendly.
I have never used Google Maps API before, so for those that have experience in it, please guide me.
Google Maps API : http://www.google.com/enterprise/mapsearth/products/mapsapi.html#
Google Maps Coordinate: http://www.google.com/enterprise/mapsearth/products/coordinate.html?rd=1#
On a side note, I might sell the application (using subscription), so I would need the Google Maps API license. Anyone know how much it is and how is the procedure? (e.g., monthly or yearly basis, per user or per use, etc.)
EDIT
Or is there any other API for the mapping? something like Google Maps API.
We have to give latitude and longitude .
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
window.onload = function () {
var mapOptions = {
//give latitude and long
center: new google.maps.LatLng("18.9750", "72.8258"),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var infoWindow = new google.maps.InfoWindow();
var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
//give latitude and long
var myLatlng = new google.maps.LatLng("18.9750", "72.8258");
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: "Mumbai"
});
}
</script>
<div id="dvMap" style="width: 500px; height: 500px">

List of bus stops from Google Maps

I am trying to build web app where you input your address and it will give you list of bus stops in your area. I want to use Google Maps for this, but i can't find the way to use them for this. Is there any way to get list of points on maps in, lets say, JSON or XML format? I tried Google Maps Places API, but it didn't work this way. Only thing i found is this example - http://gmaps-samples-v3.googlecode.com/svn/trunk/localsearch/places.html but thats not what i need.
So, anyone knows?
The Google Places API does have stop information on there but you need to form your query very specifically to make it work.
The key is using the nearby search with rankby=distance and radius= and types=bus_station
The default rankby prominence rarely shows bus stations.
Sample query:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=49.89458,-97.14137&sensor=true&key=your_key&rankby=distance&types=bus_station
I think it can help you
<script>
// This example requires the Places library. Include the libraries=places
// parameter when you first load the API. For example:
// <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places">
var map;
var infowindow;
function initMap() {
var pyrmont = {lat: 38.06908229560463, lng: 46.31730562744135};
map = new google.maps.Map(document.getElementById('map'), {
center: pyrmont,
zoom: 15
});
infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.nearbySearch({
location: pyrmont,
radius: 1000,
types: ['bus_station','transit_station']
}, callback);
}
function callback(results, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
createMarker(results[i]);
}
}
}
function createMarker(place) {
var placeLoc = place.geometry.location;
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(place.name);
infowindow.open(map, this);
});
}
</script>
Ali Seify's answer is correct except that the API document states that only the first element in the types parameter will be used by the API and the transit_station type is the correct type for bus stop.
Also, in order to get the nearest bus stop, suggest to use parameter rankBy: google.maps.places.RankBy.DISTANCE and radius parameter cannot be used in this case.
service.nearbySearch({
location: pyrmont,
rankBy: google.maps.places.RankBy.DISTANCE,
types: ['transit_station']
}, callback);
This is not a service that Google provides. They surely have all of the stuff you need on record, but they do all of their calculations internally.
One option (which might be a bit difficult) is to mine public transportation schedules for their bus stop locations. It might be an option if you have a small region (ie. a city) that your web app is to support. It's risky because if the pages change then you'll have to reconfigure the data mining application, but you'd still have the same problem trying to mine the data from Google (or somewhere else) - if you could find a way to get a bus stop list with locations and built your app around it, it could change at any time and break your application.
You could use Google Fusion Tables for this. You would have to enter the data yourself though, unless someone else already have entered it. Google maps API supports Google Fusion Tables.

Getting Address from Google Map (Reverse Geocoding)

I have a online shop and people buy products and we send a products to their address , but sometimes customers enter a bad address and we couldn't find the destination.
I want to show a Google map in address form then customer locate their address on the map and finally address of that point fetched from Google map.
Is Google offers this feature?
You can also check the address against known deliverable addresses within the area. This database is maintained by the USPS, who visits (practically) every address every single weekday. Using a web-based API you could query the database and either get an automatic match or get a list of suggested matches. I know this doesn't provide you a map, but in many cases, it can allow your clients to correct their address right there on the spot and can be very easy to implement and use. Some services offer a Javascript implementation as well as an XML hook into the API. If you're googling it, look for address verification webservice, or something similar.
I work for an address verification service called smartystreets.
Yes, this service is known as reverse geocoding.
And it's actually quite simple to implement. Assuming you get lat and long values from map click event, like so:
var map;
function initialize() {
var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
var myOptions = {
zoom: 4,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
google.maps.event.addListener(map, 'click', function(event) {
getAddress(event.latLng);
});
}
function getAddress(location latlng) {
var geocoder;
var map;
var infowindow = new google.maps.InfoWindow();
var marker;
function initialize() {
geocoder = new google.maps.Geocoder();
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
}
Take a look at reverse geocoding.Although your question is many questions in one and you should break it to smaller ones and ask them here also.

How can I center google map based on countrycode?

According to the documentation, I found out this :
geocoder.setBaseCountryCode(countrycode);
However this did not work even if I hard codded the country code ( both cases :small-capital).
Any help?
geocoder.setBaseCountryCode() will not center the map. That will set the base country for geocoding, so that if you try to geocode 'Plymouth', it will distinguish between the UK and the Massachusetts cities.
If you want to specify the country code manually, you could use the GClientGeocoder as follows:
var country_code = "ES"; // Change the country code here
function initialize() {
if (GBrowserIsCompatible()) {
var map = null;
var geocoder = null;
map = new GMap2(document.getElementById("map_canvas"));
geocoder = new GClientGeocoder();
if (geocoder) {
geocoder.getLatLng(
"Country: " + country_code,
function(point) {
if (point) {
map.setCenter(point, 13);
}
}
);
}
}
}
There is no need to use set the setBaseCountryCode() in this case, because country codes are obviously unique.
If you are using version 3 of the Google Maps API, you may want to use the google.loader.ClientLocation to center the map automatically to the client's country as in this Google Demo. This uses the IP address of the client to determine the country.
The code would look something like this:
function initialize() {
// Initialize default values
var zoom = 3;
var latlng = new google.maps.LatLng(37.4419, -100.1419);
// If ClientLocation was filled in by the loader, use that info instead
if (google.loader.ClientLocation) {
zoom = 13;
latlng = new google.maps.LatLng( google.loader.ClientLocation.latitude,
google.loader.ClientLocation.longitude);
}
var myOptions = {
zoom: zoom,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map"), myOptions);
}
Note that geolocation from IP addresses is not a very reliable science. You will be getting the location of your ISP, which can be quite far away, and in addition the IP-to-location databases aren't always up to date with the latest changes, so you might not have any data for a particular IP address. However since you would be checking for just the country, the margin of error would be quite small.
Just in case if you are looking for SQL file which has ISO country codes (both 2 and 3 chars), then you might also want to look # http://27.org/isocountrylist/
Get information from this Country database.
Pick the capital-city of the required country and center the map around that.