Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to select particular city on google map but I cant find the way.


migration rejected from Feb 22 at 20:24

This question came from our site for professional and enthusiast programmers. Votes, comments, and answers are locked due to the question being closed here, but it may be eligible for editing and reopening on the site where it originated.

closed as off-topic by Keltari, Steven, Jonno, Ben N, Hennes Feb 22 at 20:24

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question is not about computer hardware or software, within the scope defined in the help center." – Keltari, Steven, Jonno
If this question can be reworded to fit the rules in the help center, please edit the question.

This is a programming forum, you should ask this question on – Tony The Lion Nov 30 '09 at 10:31
google maps can be incorporated on web pages and has it's own scripts. This is a valid question, if poorly worded, do not close. – Jonathan Fingland Nov 30 '09 at 10:44
@Jonathan - I agree. I have seen this sort of question before in the google-maps tag. – RedBlueThing Nov 30 '09 at 22:33
I do not find it clear what you are asking. Do you want to know how to simply use Google maps? Do you want to program some input to automatically look things up? ... – Hennes Feb 22 at 20:24

Assuming you have the latitude and longitude (31.2 and 121.5 in this example) You need to call setCenter on the GMap2 object (for Google Maps version 2.*):

map.setCenter(new GLatLng(31.2, 121.5), 6);

If you don't have the latitude and longitude for the particular city (and want it to work for any city name), then you need to use the Geocoding to map from a name to a latitude longitude.

To do this you need to have a look at the documentation for the GClientGeocoder object. You will need to call getLocations, passing in a string containing the city name you are after. Once you get your asynchronous response back with a latitude, longitude, you can set the center of your map at that position.

You can find an example of geocoding several city names here.

  1. you need the database of all zip codes in your country in following format(I mean coordinates for zip code areas)


<geo><ps><p><c t="37.789829" n="-122.403842"></c><c t="37.790286" n="-122.403934"></c><c t="37.79076" n="-122.404031"></c><c t="37.791691" n="-122.40422"></c><c t="37.792639" n="-122.404418"></c><c t="37.793565" n="-122.404613"></c><c t="37.793646" n="-122.404016"></c><c t="37.79378" n="-122.402957"></c><c t="37.79388" n="-122.40216"></c><c t="37.793987" n="-122.401315"></c><c t="37.793544" n="-122.401225"></c><c t="37.793694" n="-122.400058"></c><c t="37.793209" n="-122.399959"></c><c t="37.792258" n="-122.399763"></c><c t="37.791327" n="-122.399572"></c><c t="37.791325" n="-122.399494"></c><c t="37.791017" n="-122.399149"></c><c t="37.790997" n="-122.399255"></c><c t="37.790805" n="-122.399505"></c><c t="37.790493" n="-122.399896"></c><c t="37.79029" n="-122.400152"></c><c t="37.789348" n="-122.401348"></c><c t="37.789264" n="-122.401375"></c><c t="37.789244" n="-122.401479"></c><c t="37.789205" n="-122.401528"></c><c t="37.789029" n="-122.401749"></c><c t="37.788878" n="-122.401939"></c><c t="37.788721" n="-122.402066"></c><c t="37.7887" n="-122.40217"></c><c t="37.78828" n="-122.402702"></c><c t="37.788197" n="-122.402807"></c><c t="37.788112" n="-122.402914"></c><c t="37.787725" n="-122.403403"></c><c t="37.787642" n="-122.403431"></c><c t="37.787963" n="-122.403492"></c><c t="37.788427" n="-122.40358"></c><c t="37.788894" n="-122.403661"></c><c t="37.789363" n="-122.403747"></c><c t="37.789829" n="-122.403842"></c></p></ps><metadata></metadata></geo>


  1. You need the database of all zip codes for the county / city

For example San Francisco has 94101,94102,94103. Etc.

  1. When you want to show the city on map you will have to show all areas for all zip codes for that city.

here is the code for one zip area

var markers = [];

function show_zip($map,$zip_code){

var c,g,h; $.get("coordinates/zip/"+$zip_code+".txt",{},function(a){ var f=0,d,e; $(a).find("ps").each(function(){ $(this).find("p").each(function(){ var a=[]; $(this).find("c").each(function(){ c=$(this); g=c.attr("t"); h=c.attr("n"); a.push(new google.maps.LatLng(g,h))}); e=new google.maps.Polygon({paths:a, strokeColor:"#FF0000", strokeOpacity:0.8, strokeWeight:3, fillColor:"#FF0000", fillOpacity:0.35, zIndex:1 }); e.setMap($map);


f++; }); }); });


As the result you should get something similar to this

screen shot from working system