Introduction

This article explains the use of Google Maps in the Web API. This map contains the Country or City name. It does not contain the Latitude and Longitude. By using Google Maps we can search any Country and any City in the Country or all over the world.
The following is the procedure.
First, we create a web application as in the following:
map.jpg
map1.jpg
Now we use the "index.cshtml" file for writing some script and HTML code. This file exists:
map2.jpg
Add the following code:
  1. <!DOCTYPE link href="https://maps/documentation/javascript/examples/default.css" rel="stylesheet" />
  2. <html>
  3. <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false" type="text/javascript"></script>
  4. <script>
  5. var mapcode;
  6. var diag;
  7. function initialize() {
  8. mapcode = new google.maps.Geocoder();
  9. var lnt = new google.maps.LatLng(26.45, 82.85);
  10. var diagChoice = {
  11. zoom: 9,
  12. center: lnt,
  13. diagId: google.maps.MapTypeId.ROADMAP
  14. }
  15. diag = new google.maps.Map(document.getElementById('map-canvas'), diagChoice);
  16. }
  17. function codeAddress() {
  18. var add = document.getElementById('address').value;
  19. mapcode.geocode({ 'address': add }, function (results, status) {
  20. if (status == google.maps.GeocoderStatus.OK) {
  21. diag.setCenter(results[0].geometry.location);
  22. var hint = new google.maps.Marker({
  23. diag: diag,
  24. position: results[0].geometry.location
  25. });
  26. } else {
  27. alert('This code is not successful ' + status);
  28. }
  29. });
  30. }
  31. google.maps.event.addDomListener(window, 'load', initialize);
  32. </script>
  33. <body>
  34. <div id="panel">
  35. <input id="address" type="textbox" value="New Delhi">
  36. <input type="button" value="Search" onclick="codeAddress()">
  37. </div>
  38. <div id="map-canvas" style="width: 600px; height: 390px; border: 5px solid #5E5454;">
  39. </div>
  40. </body>
  41. </html>
There is various status code that returns the following values:
Execute the application by pressing "F5".
map3.jpg
Type any city into the TextBox for the search:
map4.jpg