Google Map Pin with city/country field - google-maps

I know it's possible to drop pins on a google map with the LAT/LONG variables. I was wondering if it's possible to drop pins with city/country fields. I have a registration form that allows the user to enter his address and wondering if any of those address variables (city, state, country, postal/zip code) can be used to create the pin on the map.. As opposed to asking the client to search and enter the LAT / LONG?
Thank you

You will need to use geocoding services to convert the address to a lat/long. You can try Google's API, or some other such as geocoder.us

Related

Google Map API for addesses search

I have been searching for some information on what I want to achieve but not getting any clear answers.
I have a database with thousands of addresses. I want that when the user searches by entering a postcode, the search should show all the available addresses close to the postcode in a map. Zooming In would obviously show closer address to the search postcode (and hence less search results) and zooming out would also include farther addresses (and hence more search results). And then clicking the location icon would display the complete address.
Do I need to store the addresses as longitude and latitude or google map can search a location using postcode? If I need to store the longitude and latitude then whats the best way to convert an address to long and lat?
I really appreciate if you can point me to any useful links or reusable code.
Thanks
As I understand it, you want to find all closest locations from YOUR data to some location, which is identified by a postcode.
First, you have to convert all your addresses to coordinates (Latitude and Longitude). You can do that using Google Geocode API, you will have to create as script, which calls Google Geocode API for every single address in your db:
https://maps.googleapis.com/maps/api/geocode/json?address=EXAMPLE_ADDRES&key=YOUR_API_KEY
The response this script brings you is documented here. You can parse it to get latitude and longitude for each locations and store them in your database. BEWARE of limitations of the Google Geocode API. They are listed here. You have to create your script in a way that won't exceed those limits. Also read this article for caching the results of geocoding, to make sure you don't violate the terms of service. The article also contains some best practices and examples of server side geocoding.
Now, when somebody inputs postcode to your application, you can use the geocoding API or Google maps Geocoding service to translate postcode to coordinate and using haversine formula you can calculate the closest locations from your db, to coordinates of the postcode location. You can do that on frontend side, example in this SO answer (instead of address you will input postcode + state/country in the address bar) or on backend side, if you use MySQL check this SO question.

Is there a way to geocode a MySQL database, then display results on a Google Map?

Is there a way to geocode a MySQL database, then display results on a Google Map?
Tables are stored as zipcode, name, state, and address. I'm looking to see if there's a way to convert these to coordinates and display them on a map automatically using some sort of API or code.
https://developers.google.com/maps/documentation/javascript/geocoding
Essentially, you would pass the zipcode/some kind of concatenation of the address to the Geocode API, which would return you a result as a LatLng object/some address components. You can then use the marker object to display those results.

Website; let user add location and get coordinates

I've been developing a website where users can add a place (say a store in a city) and it is stored in a database. Now I would like to be able to display these places on a interactive map on my website. I got a bing maps developer key but it seems i can only display the data if i have the coordinates (lon/lat). Is that true? And if so, how do I get the coordinates automatically once a user adds new data?
As an example: You add Store XYZ in City XYZ, but you DON'T have to enter the coordinates. Now, this info is stored, but I don't have the coordinates..
Any help is much appreciated!
If you don't have any plans on allowing your users to insert place locations in a map or by filling some lat/long data, I suggest you to use google web services to get geolocation of those places. You'll need to format the input you send into something like an address to get it working properly though.
See this Google documentation

How do I move marker to the street in front of address

I am using the google geocodeing and for a lot of the rural addresses the marker gets placed in the middle of the lot. What I need to have is the marker placed on the street in front of the address that was geocoded.
Here is a link to what I currently have for testing.
http://www.commsoft.net/maps/index.html
Any suggestions would be greatly appreciated.
You could possibly use the Google Maps API StreetViewService to get the street location you need.
Google Maps API - Directly Accessing Street View Data
Get the latLng location using the Geocoder
Send that location, a search radius, and a callback function to the streetview service:
var streetViewService = new google.maps.StreetViewService();
streetViewService.getPanoramaByLocation(location, searchRadius, callbackFunction);
The streetViewService will respond with the closest streetView photo it has to your location. In your callback function, callbackFunction(data, status), data.location.latLng will contain the location on the street where that streetview photo was taken.
Use that location for your marker.
It isn't a perfect solution, but it might be the best you can do, short of storing your own street locations in a database. The main drawback is that, in order for it to work, the address must have a streetview image. So if you are mostly concerned with rural addresses, it might not work for you.
The best way to display multiple addresses on a Google Maps API map is to geocode them off-line and store the coordinates in your database (or where ever you are getting the addresses from). If you are going to display more than 10-15 markers using the geocoder or the directions service, you will run into the quota/rate limits.
If you geocode the addresses off line, if you don't like the values that are returned by the geocoder, you can fix them.
An option for programmatically getting coordinates on the street nearest an address is to use the directions service (get directions from the address of interest to itself, should result in a zero length route with the same start and end point on the road at the point closest to the address).
example using your addresses

What's the best Street Address Search service?

I'm impressed with the simplicity of Microsoft's Virtual Earth Street Address search service.
My requirement is to type rough address info with no comma separators into a simple text box, press a find button, wait a few seconds and then observe a result picklist.
I mocked up something here using the virtual earth SDK.
Does Google Maps have a similar API?
Which street address search service is better?
Yes.
There is a bit of information in these related questions:
How do you perform address validation?
How to obtain longitude and latitude for a street address programmatically (and legally)
There's also the yahoo maps API