Results 1 to 1 of 1

Thread: Mapping latitude and longitude, marker position is wrong, it geocodes nearest addess

  1. #1
    Thread Starter
    Member surfcrf450's Avatar
    Join Date
    Apr 2011
    Location
    United States
    Posts
    84
    Thanks
    8
    Thanked 6 Times in 5 Posts

    Mapping latitude and longitude, marker position is wrong, it geocodes nearest addess

    I have made countless adjustments to sidebar-gmap.php trying to correct the issue, but can't get it and was hoping someone might be able to help.

    I have cp_street inputting lat,lng variables. The code below is working enough to get a marker, but the marker is positioning on the nearest known address and not the actual lat long coordinates.

    Here is what my sidebar-gmap.php code is looking like:

    PHP Code:
    <div id="gmap" class="mapblock">

        <?php
                $make_address 
    get_post_meta($post->ID'cp_street'true);
        
    ?>

        <script type="text/javascript">var address = "<?php echo esc_js($make_address); ?>";</script>

        <?php cp_google_maps_js(); ?>

        <!-- google map div -->
        <div id="map"></div>

    </div>


    <?php
    // Google map on single page
    function cp_google_maps_js() {
    ?>
     <script type="text/javascript">
    //<![CDATA[
        jQuery(document).ready(function($) {
            $('#map').hide();
            load();
            $('#map').fadeIn(1000)
            codeAddress();
        });

        //var directionDisplay;
        //var directionsService = new google.maps.DirectionsService();
        var map = null;
        var geocoder = null;
        var fromAdd;
        var toAdd;
        var redFlag = "<?php echo get_bloginfo('template_directory'?>/images/red-flag.png";
        var shadow = "<?php echo get_bloginfo('template_directory'?>/images/red-flag-shadow.png";
        var noLuck = "<?php echo get_bloginfo('template_directory'?>/images/gmaps-no-result.gif";
        //var title = "<?php esc_js(the_title()); ?>";
        var contentString = '<div id="mcwrap"><span><?php esc_js(the_title()); ?></span><br />' + address + '</div>';

        function load() {
            geocoder = new google.maps.Geocoder();
            //directionsDisplay = new google.maps.DirectionsRenderer();        
            var address = new google.maps.LatLng(18.245003,-66.401825);
            var myOptions = {
                zoom: 14,
                center: address,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                mapTypeControlOptions: {
                    style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
                }
            }
            map = new google.maps.Map(document.getElementById('map'), myOptions);
            //directionsDisplay.setMap(map);
        }


        function codeAddress() {
            geocoder.geocode( { 'address': address }, function(results, status) {
              if (status == google.maps.GeocoderStatus.OK) {
                map.setCenter();

                var marker = new google.maps.Marker({
                    map: map,
                    icon: redFlag,
                    shadow: shadow,
                    //title: title,
                    animation: google.maps.Animation.DROP,
                    position: results[0].geometry.location                
                });

                var infowindow = new google.maps.InfoWindow({
                    maxWidth: 270,
                    content: contentString,
                    disableAutoPan: false
                });

                infowindow.open(map, marker);

                google.maps.event.addListener(marker, 'click', function() {
                  infowindow.open(map,marker);
                });

              } else {
                (function($) {
                    $('#map').append('<div style="height:400px;background: url(' + noLuck + ') no-repeat center center;"><p style="padding:50px 0;text-align:center;"><?php echo esc_js(__('Sorry, the address could not be found.''appthemes')); ?></p></div>');
                    return false;
                })(jQuery);
              }
            });
          }

        function showAddress(fromAddress, toAddress) {
            calcRoute();
            calcRoute1();
        }
        function calcRoute() {
            var start = document.getElementById("fromAdd").value;
            var end = document.getElementById("toAdd").value;
            var request = {
                origin: start,
                destination: end,
                travelMode: google.maps.DirectionsTravelMode.DRIVING
            };
            directionsService.route(request, function(response, status) {
                if (status == google.maps.DirectionsStatus.OK) {
                    directionsDisplay.setDirections(response);
                }
            });
        }
    //]]>
    </script>


    <?php

    }

    ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 8
    Last Post: November 2nd, 2011, 09:26 PM
  2. [MOD NEEDED] Saving longitude and latitude values.
    By johnster in forum ClassiPress General Discussion
    Replies: 1
    Last Post: August 11th, 2010, 07:44 AM
  3. Map marker
    By greencode in forum ClassiPress General Discussion
    Replies: 0
    Last Post: April 22nd, 2010, 06:32 AM