doucanshou6998 2019-01-01 04:31
浏览 62
已采纳

使用MYSQL加载Google Markers

I've looked up other examples of this question on Stack, but they either use JQUERY or load using XML etc, which is NOT what I'm using to populate my Map.

Map works perfectly fine, but marker doesn't work when I attempt to reference a PHP variable as LatLng. I've tried to echo the LatLng Variable and use Heredocs but nothing works.

<? php
    // I MADE QUERIES HERE AND ADDED THEM INTO "$coords"


echo<<<_

    <!DOCTYPE html>
    <html>
    </style>
    <body>
    <div class="Banner">
        <div class="TitleText">Sonic Strains &copy;</div>
    </div>
    <div class="login">Logout</div>
    <div class="gallery" id="container">
        <div class="map" id="mapInsert"></div>
        <div class="navButton">Start Nav</div><div class="orderButton">Order Details</div>
        <div class="abortButton">Abort</div><div class="confirmButton">Confirm</div><div class="disclaimer"></div>
    </div>
    <script>
          function initMap() {  
            navigator.geolocation.getCurrentPosition(function(position) {
                var initialLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
                var Map = new google.maps.Map(document.getElementById('mapInsert'));
                Map.setCenter(initialLocation);
                Map.setZoom(8);
            }, function(positionError) {
                //---------- User denied geolocation prompt - default to Chicago
                Map.setCenter(new google.maps.LatLng(39.8097343, -98.5556199));
                Map.setZoom(5);
            },{enableHighAccuracy:true, timeout: 3000, maximumAge:1000});}
                //MAKE ANOTHER MARKER FOR THE CLIENT LOCATION
                var userLocation = {lat:$coords[user_lat], lng:$coords[user_long]};
                var marker = new google.maps.Marker({
                    position:userLocation, 
                    map:Map,
                    draggable:false, 
                    clickable:false
                });
                marker.setMap(Map);}
    </script>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=[API_KEY]&callback=initMap" 
        async defer></script>
    </body>
    </html>


_;

?>

Error--

"SyntaxError: Unexpected token <"

This is where I try an reference the PHP LatLng Marker Position, why doesn't it allow me to reference PHP?

  • 写回答

2条回答 默认 最新

  • douwei2825 2019-01-01 19:25
    关注

    The issue was that the marker declaration was outside of the initMap(). When I moved the marker inside of the Main Function it worked

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分