Google Map在数据库中解决地址问题

编程入门 行业动态 更新时间:2024-10-21 03:55:53
本文介绍了Google Map在数据库中解决地址问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

此行不起作用,并且控制台中没有错误.

this line is not working and no error in console.

position: new google.maps.LatLng( coordsArray[i].location ),

通过alert(coordsArray[i].location);位置确认的数据是数据库字段,返回LatLng -43.59670,172.38247作为字符串.

data confirmed by alert(coordsArray[i].location);location been database field returning LatLng -43.59670,172.38247 as a string.

此行有效:position: new google.maps.LatLng( -43.59670,172.38247 ), 与上述相同的数据是什么,我的代码有什么问题吗?

This line works: position: new google.maps.LatLng( -43.59670,172.38247 ), What is the same data as above, any ideas what wrong with my code?

var list_location = localStorage.getItem('myHouse'); var obj = JSON.parse(list_location); var coordsArray = obj; var marker; var locX; var image = 'apppics.weebly....png'; var map = Appery("googlemap_6").options.mapElement.gmap('get', 'map'); var CreateMarker = function(coordsArray, i){ var marker = new google.maps.Marker({ position: new google.maps.LatLng( coordsArray[i].location ), //position: new google.maps.LatLng( -43.59670,172.38247 ), title: coordsArray[i].storeName, map: Appery("googlemap_6").gmap, }); for (var i = 0, j = coordsArray.length; i < j-1; i++) alert(coordsArray[i].location); CreateMarker(coordsArray, i);

推荐答案

这是错误的:new google.maps.LatLng(coordsArray[i].location).

您说:位置已在数据库字段中返回LatLng -43.59670,172.38247作为字符串."

You state: "location been database field returning LatLng -43.59670,172.38247 as a string."

google.maps.LatLng 构造函数需要两个数字作为参数(不是逗号分隔的字符串).

the google.maps.LatLng constructor takes two numbers as arguments (not a comma separated string).

如果coordsArray[i].location是逗号分隔的字符串,请将其转换为两个数字.

If coordsArray[i].location is a comma separated string, convert it to two numbers.

var coords = coordsArray[i].location.split(","); var latLng = new google.maps.LatLng(parseFloat(coords[0]), parseFloat(coords[1])); var marker = new google.maps.Marker({ position: latLng, map: map });

代码段:

var geocoder; var map; function initialize() { var map = new google.maps.Map( document.getElementById("map_canvas"), { center: new google.maps.LatLng(37.4419, -122.1419), zoom: 13, mapTypeId: google.maps.MapTypeId.ROADMAP }); var location = "-43.59670,172.38247"; coords = location.split(","); var latLng = new google.maps.LatLng(parseFloat(coords[0]), parseFloat(coords[1])); var marker = new google.maps.Marker({ position: latLng, map: map }); map.setCenter(latLng); } google.maps.event.addDomListener(window, "load", initialize);

html, body, #map_canvas { height: 100%; width: 100%; margin: 0px; padding: 0px }

<script src="maps.googleapis/maps/api/js?"></script> <div id="map_canvas"></div>

更多推荐

Google Map在数据库中解决地址问题

本文发布于:2023-10-30 04:24:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1541757.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库中   地址   Google   Map

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!