Getting the longitude and latitude of a region from a webservice - javascript

I am building a JS application which uses google maps and needs the ability to have polygons over the states (the same shape as the state) to which colors can be applied. Something like this:
http://econym.org.uk/gmap/example_states4.htm
I can get something set up similar to that, but I don't have XML or data for any other regions.
What I'd really like is to be able to call a webservice with a given state, country, region, etc. and retrieve a series of lat/long coordinates laying out the given region. I've done some initial research but haven't found anything that seems to be up to task.
Can anyone recommend a solution?

Here is a KML of all US states and capitals. You can extract the states boundaries from that file or just use the KML itself. USA States KML

Related

How to get only street/road coordinates via reverse geocoding (Google Maps API)

I'm looking for a solution to get data to create a simple roads-only map.
Within a small area specified by lat/long I need data that allows me to draw custom lines between given street coordinates (start and endpoints are basically enough and only from major streets). Coordinates from intersections are also fine to connect those with my custom lines.
Another approaches would be to get all the major street names within the specified area via reverse geocoding and then - somehow - get coordinates for each of this streets.
There was a similar request a couple years ago:
Get street graph for a game using Google Maps API and I'm wondering is it still a big deal to achieve this kind of technical information in a simple way?
EDIT:
I researched the topic but no result gave me the satisfaction I was looking for. For instance Google's Directions/Roads API are both depending on routes. OSM/Google Maps API are filled with information around a specified geo location but without any technical data I need. To be simple: An Array of intersection/street-point coordinates (are they even called coordinates?!).
I think I'm lost - or even stuck - in terms of my own search phrases. I'm not looking for a copy & paste snippet more like a direction or some hints where to focus next or how it is done.
With the clarification of geocodezip's comment I've found the following related question:
How to get all roads around a given location in OpenStreetMap?
This fully suits my demand to get specific road information within a certain location using OSM instead of Google Maps API.
Many thanks

Set view for an array of addresses(no coordinates) using leaflet js

I don't have latitude and longitude coordinates to set view on leaflet js library. I had an array of objects which contains city and state, country as properties.Now i want to set the markers on the map using leaflet js for this array. What could be the better way to do this?
You need something called a geocoder, that can help you look up the latitude and longitude given the name of a geographic place.
Geocoders are typically quite complicated pieces of software that you run on a server. Fortunately, there are several available that you can use from an HTTP interface, as well as Leaflet plugins to communicate with them.
On Leaflets plugin page (http://leafletjs.com/plugins.html), under the section Geocoding (address lookup), you can find several plugins that might interest you.
For example, you can use Leaflet Control Geocoder (disclaimer: I'm the author of this plugin) that you can either add to the map to let a user search directly, or you can use classes that communicate with the geocoding services directly, to lookup geo coordinates from any string - see for example the class L.Control.Geocoder.Nominatim to use OpenStreetMap's Nominatim geocoding service.

Map Boundary Service Area System

I currently have a service area system based on zipcodes, customers would enter an address(zipcode) and it would return the available service times for their service area (a service area can have multiple zipcodes), what I need to do now is instead of using zipcodes to create service areas I need to use a boundary system where I can draw polygons on a map and when customers enter an address we would geocode it and compare against the service area and return appropriate service time, a system like this would be more accurate because the problem I have now is that zipcode boundaries are of very different shapes and it is impossible to make an accurate service time map. I'm having problems thinking of an easy way to accomplish this.
to get you started:
Google Maps tutorial
After researching deeper on this topic, I found what I was looking for!, I could use the ray-casting algorithm to spot a point(coordinates) inside a polygon, the polygon's coordinates I can easily get from Google maps, In essence what I will be doing is:
Make a Google maps area selector to build polygons.
Save polygons point coordinates array to database.(as service region/area)
Geo-Code customers addresses and save to DB as well (First time will pull from Google maps and save on DB for future use).
4.Use the Ray-Casting Algorithm to loop through all the "polygons" until it returns true and we would know to what polygon the address belongs to, if it returns false then we know we don't service that area.
References:
Raycasting algorithm with GPS coordinates
http://rosettacode.org/wiki/Ray-casting_algorithm

Google Map Location constructor with general location type

I have been using Google maps api to get customer to a specific location using a constructor like this
new google.maps.LatLng(42.999, 54.000);
With the exact longitude and latitude as the arguments. What I want to do now is not use the lat, long option and use a keyword like rest area that would bring up the closet rest area. I am not quite finding it in Google map api here https://developers.google.com/maps/documentation/javascript/reference
Can some one help me come up with a constrctor that can take a key word and locate the nearest one in googLe maps.
You're going to have to use the google geocoding API.
Basically you do a request to google with a search string and it returns an object containing the long/lat for areas it may have found... There's a lot of options in there and you can do fairly neat tricks which are already carefully explained by google themselves.
https://developers.google.com/maps/documentation/geocoding/
There are some limitations to the # of requests you can make per-day. To keep this to a minimum you can ofcourse make a server side script that pre-fetches results for things that will be re-used (for example the long/lat for office location of a large enterprise which may have a dot on a map on the website...).
Simplest way would be to make a json request with a few parameters and parse the return json in js, like getting the long/lat of the first result returned.
If I understand correctly, you want to use keyword search for things around a particular location. I would suggest using the Places library of the Google Maps API:
https://developers.google.com/maps/documentation/javascript/places#place_searches
This allows you to search by category or by keyword over Google's datastore of 10s of millions of Places.

Google Maps API - point of interests

I am working now on little project.
In one view i am returning data for google maps API (longitudes and latitudes).
Under the map I have to implement few buttons to add point of interests on the map in this location which is actually showed.
There could be some buttons/types of POI like schools, banks, atms etc.
So, let's go back. When I put all my markers on map how to add there points of interests?
I would like to get below data for them:
longitude (needed for show)
latitude
type
title
description
I know, that there is google local ajax search api, but I am not sure if it is correct way to do.
I know how to find this data using google maps interface, for example:
Example Map
http://maps.google.pl/maps?f=q&source=s_q&hl=pl&geocode=&q=category:%22Banks+%26+Financial+Institutions%22&sll=51.510202,-0.12144&sspn=0.01859,0.05549&ie=UTF8&cd=1&ei=N4hUS7ynEc7AjAeWtNm4CA&radius=1.19&rq=1&ev=zi&hq=category:%22Banks+%26+Financial+Institutions%22&hnear=&z=15
but how to do this using API?
Thanks.
The Google Local Search API can be used to obtain a small number of such points at a time, as in this example. Or you could just add the Googlebar to your Maps AVI v2 map.
Access to large numbers of such points at once is not available from Google, and is generally not available for free.
In addition to Google, there are other data providers you can use. For example, the API at http://compass.webservius.com allows you to retrieve data on more than 16 million businesses in the US (including name, lat/long, business type / industry code, etc).
The Google API is a Javascript API.
If I understand you correctly, you want to add markers on a Google Map using the Google Maps API.
The documentation suggests that either you hardcode your Markers or create one by creating a Marker Manager.
I have never used Google Maps API but if you want more info, visit the documentation here.
Good luck!

Categories

Resources