Advertisement
Guest User

locationview

a guest
Oct 6th, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <!--
  3. To change this license header, choose License Headers in Project Properties.
  4. To change this template file, choose Tools | Templates
  5. and open the template in the editor.
  6. -->
  7. <html>
  8. <head>
  9. <meta charset="UTF-8">
  10. <title></title>
  11. <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false">
  12. </script>
  13. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
  14. <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
  15. <script>
  16. $(document).ready(function() {
  17. function submitMe(selector)
  18. {
  19. //alert(selector);
  20. $.ajax({
  21. type: "POST",
  22. url: "<?php echo base_url(); ?>" + "index.php/locationcontroller/getLocation",
  23. data: {location:selector },
  24. success:function(longitude){
  25. // alert(selector);
  26. locate=longitude.split(" ");
  27. latlong(locate[0],locate[1],selector);
  28.  
  29. }
  30.  
  31. });
  32. }
  33.  
  34. $('#address').blur(function(){
  35. var add=$('#address').val();
  36. // alert(add);
  37. submitMe(add);
  38. });
  39.  
  40.  
  41. });
  42. function latlong(lat,long,selector)
  43. {
  44.  
  45. alert(lat);
  46. alert(long);
  47. var selector=selector;
  48. var myLatlng = new google.maps.LatLng(lat,long);
  49. var map;
  50. var marker;
  51.  
  52. var geocoder = new google.maps.Geocoder();
  53. var infowindow = new google.maps.InfoWindow();
  54. function initialize(){
  55. var mapOptions = {
  56. zoom: 18,
  57. center: myLatlng,
  58. mapTypeId: google.maps.MapTypeId.ROADMAP
  59. };
  60.  
  61. map = new google.maps.Map(document.getElementById("myMap"), mapOptions);
  62.  
  63. marker = new google.maps.Marker({
  64. map: map,
  65. position: myLatlng,
  66. draggable: true
  67. });
  68.  
  69. geocoder.geocode({'latLng': myLatlng }, function(results, status) {
  70. if (status == google.maps.GeocoderStatus.OK) {
  71. if (results[0]) {
  72. $('#latitude,#longitude').show();
  73. selector=results[0].formatted_address;
  74. $('#latitude').val(marker.getPosition().lat());
  75. $('#longitude').val(marker.getPosition().lng());
  76. infowindow.setContent(results[0].formatted_address);
  77. infowindow.open(map, marker);
  78. }
  79. }
  80. });
  81.  
  82. google.maps.event.addListener(marker, 'dragend', function() {
  83.  
  84. geocoder.geocode({'latLng': marker.getPosition()}, function(results, status) {
  85. if (status == google.maps.GeocoderStatus.OK) {
  86. if (results[0]) {
  87. selector=results[0].formatted_address;
  88. $('#latitude').val(marker.getPosition().lat());
  89. $('#longitude').val(marker.getPosition().lng());
  90. infowindow.setContent(results[0].formatted_address);
  91. infowindow.open(map, marker);
  92. }
  93. }
  94. });
  95. });
  96.  
  97. }
  98. google.maps.event.addDomListener(window, 'load', initialize);
  99.  
  100. }
  101. </script>
  102. </head>
  103. <body>
  104. <form method="POST">
  105. <div id="myMap"></div>
  106. <!--<input id="" type="text" style="width:600px;"/><br/>-->
  107. <input type="text" id="address" name="address" />
  108. <input type="text" id="latitude" placeholder="Latitude"/>
  109. <input type="text" id="longitude" placeholder="Longitude"/>
  110. <input type="submit" name="submit">
  111. </form>
  112.  
  113. </body>
  114. <style>
  115. #myMap {
  116. height: 350px;
  117. width: 680px;
  118. }
  119. </style>
  120. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement